I new to MVC 4 .NET and currently building a website where person can enter the details of tenant and generate the payment bill accordingly. For the ActionResult Ind() i have shown the details of the tenants currently the land lord have. Now i want to generate the payment bill slips for each of the tenant(let suppose there are total 20 tenants) for that i am using following code. Please note that i have multiple tables like tb_rooms, tb_house_no, tb_tenant, tb_ebill etc.(HomeController.cs page)
public ActionResult rent_slip_print()
{
SqlDataAdapter adp = new SqlDataAdapter("SELECT tb_houseno.h_houseno, tb_rent.rent_room_id, tb_rent.rent_rent, tb_ebill.bill_miscid, tb_unit.unit_rate, tb_tenant.t_name, tb_ebill.bill_date, tb_ebill.bill_prevunit, tb_ebill.bill_presntunit, tb_ebill.bill_diff,tb_ebill.bill_ebill,tb_ebill.bill_total FROM tb_ebill INNER JOIN tb_houseno ON tb_ebill.bill_houseid = tb_houseno.h_id INNER JOIN tb_misc ON tb_ebill.bill_miscid = tb_misc.misc_id INNER JOIN tb_rent ON tb_ebill.bill_rentid = tb_rent.rent_id INNER JOIN tb_room ON tb_ebill.bill_roomid = tb_room.room_id INNER JOIN tb_tenant ON tb_ebill.bill_tenantid = tb_tenant.t_id AND tb_room.room_id = tb_tenant.t_room_id INNER JOIN tb_unit ON tb_ebill.bill_unitid = tb_unit.unit_id", con);
DataTable dt = new DataTable();
adp.Fill(dt);
List<rentslip> obj = new List<rentslip>();
for (int i = 0; i < dt.Rows.Count; i++)
{
rentslip objc = new rentslip();
objc.bill_roomid = Convert.ToInt32(dt.Rows[i]["bill_roomid"].ToString());
objc.bill_houseid = Convert.ToInt32(dt.Rows[i]["bill_houseid"].ToString());
objc.bill_rentid = Convert.ToInt32(dt.Rows[i]["bill_rentid"].ToString());
//objc.bill_prevunit = Convert.ToInt32(dt.Rows[i]["bill_prevunit"].ToString());
//objc.bill_presntunit = Convert.ToInt32(dt.Rows[i]["bill_presntunit"].ToString());
//objc.bill_date = Convert.ToDateTime(dt.Rows[i]["bill_date"].ToString());
obj.Add(objc);
}
string h = (obj.Count / 2).ToString();
retu View(obj);
}
in above code rentslip is a class which i have put into controller folder and this is the class code(rentslip.cs page)
using System.Web;
namespace RENTBUDDY_NEW_WEB.Controllers
{
public class rentslip
{
public int bill_id { get; set; }
public int bill_houseid { get; set; }
public int bill_roomid { get; set; }
public int bill_rentid { get; set; }
public int bill_unitid { get; set; }
public int bill_miscid { get; set; }
public int bill_tenantid { get; set; }
public DateTime bill_date { get; set; }
public int bill_prevunit { get; set; }
public int bill_presntunit { get; set; }
public int bill_diff { get; set; }
public int bill_ebill { get; set; }
public int bill_total { get; set; }
//public int tb_rent.rent_room_id { get; set; }
}
}
for displaying the same here is the html code(rent_slip_print.cs.html page)
@{
Layout = null;
}
<h2>rent_slip_print</h2>
<div style="border:groove;background-color:aqua;width:920px">
@foreach (var item in Model)
{
<div id="dataListItem" style="float:left;border:dotted;width:250px">
<table style="background-color:pink;width:250px">
<tr style="font:100;text-align:center"><td><b>Room No. @item.bill_id</b></td></tr>
<tr style="font:100;text-align:center"><td><b>House No. @item.bill_houseid</b></td></tr>
<tr style="font:100;text-align:center"><td><b>Rent @item.bill_rentid</b></td></tr>
<tr style="font:100;text-align:center"><td><b>Old unit. @item.bill_prevunit</b></td></tr>
<tr style="font:100;text-align:center"><td><b>Curr unit. @item.bill_presntunit </b></td></tr>
<tr style="font:100;text-align:center"><td><b>Date @item.bill_date</b></td></tr>
</table>
</div>
}
</div>
now the problem i am facing is that if i change the sql querry to simply select * from tb_ebill, it works but obviously does not provide desired result, so i want to use querry with ier joins and in that case i am not getting anything not even error but the blank page without data. i think i have to define get; set properties for the other tables also. how to do that ??
