Hello,
i am new to MVC,Can someone tell me how to use an action from controller when rendering a partial view in a view.
for example,i have a model Users:
public class items
{
public string itemname{ get; set; }
public int itemid{ get; set; }
}
and i am returning users list by using a storeproc
public static List<items> GetAvailableItems(int userid, string applicationcode)
{
var dbcontext = new MasterDataContext();
var applications = dbcontext.SPGeTItemList(userid
, applicationcode).ToList();
var appList = new List<Items>();
if (applications.Any())
{
appList.AddRange(applications.Select(apps => new Items()
{ appName = apps.APPLICATION_CODE }));
}
return appList;
}
in my controller i have an action in my controller
public ActionResult Applications()
{
const string strApplicationCode = "APP";
int userid = Convert.ToInt32(HttpContext.Current.Session["sysUserId"]);
var applist = GetAvailableItems(userid, strApplicationCode);
return PartialView(applist);
}
And partial view Items.cshtml
@model Items
@{
ViewBag.Title = "Items";
}
<h2>Items</h2>
<table>
<tr>
<th>
itemname
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.itemname)
</td>
</tr>
}
</table>
and i am rendring this partial view in my main view
@{
ViewBag.Title = "Home";
}
<div class="rdPanel">
@Html.DevExpress().RoundPanel(
settings =>
{
settings.Name = "rpFeatures";
settings.HeaderText = "Available Items";
settings.Width = 800;
settings.SetContent(() =>
{
Html.RenderPartial("Items");
} );
}).GetHtml()
</div>
But how can i use my action to get the list from db.
ThaNK YOU