I have created a mobile store project. There is a dropdown in my view, I need to fill this dropdown from database so I have declared a public variable in controller but it's not accessible in views. I have also tried to declare that in model class, it's working fine, but problem is that when I update the entity model from database these variable got deleted. So please suggest me how to do that and also I don't want to use ViewBag. Code which I have tried.
public SelectList Vendor { get; set; }
public ActionResult ShowAllMobileDetails(tbInsertMobile IM)
{
Vendor = new SelectList(db.Usp_VendorList(), "VendorId", "VendorName");
return View(IM);
}
Views..
@model MobileApplicationEntityFramework.Models.tbInsertMobile
@{
ViewBag.Title = "ShowAllMobileDetails";
}
@using (@Html.BeginForm())
{
<h2>ShowAllMobileDetails</h2>
<p>
@Html.ActionLink("Create New Mobile", "InsertMobile");
</p>
<fieldset>
<legend>Search Panel</legend>
<table>
<tr>
<td>Mobile Name</td>
<td>@Html.TextBoxFor(a => a.MobileName) </td>
</tr>
<tr>
<td>Mobile Manufacured</td>
<td>@Html.DropDownList("ddlVendor", Vendor, "Select Manufacurer")</td>
</tr>
</table>
</fieldset>
}