I am calling partial view controller through J_Query, controller action(ListInventoryProduct) is called and execute without error( the list is populated). But the partial view is not displayed. In browser Developer tool says it is internal server error. I can't figure out what is the problem.
The following is my code.
Model:
public class InventoryProductsViewModel
{
public long Id { get; set; }
[Display(Name = "Product Name")]
public string Title { get; set; }
[Display(Name = "SubCategory Name")]
public string SubCategory { get; set; }
[Display(Name = "Balance")]
public int Balance { get; set; }
[Display(Name = "Count")]
public int InventoryCount { get; set; }
[Display(Name = "Difference")]
public string Difference { get; set; }
[Display(Name = "IMEINumber")]
public string IMEINumber { get; set; }
[Display(Name = "BarrcodesString")]
public string BarrcodesString { get; set; }
public long subId { get; set; }
}
==============================
Controller Action
public ActionResult LoadInventoryProducts(long categoryId)
{
Session["Products"] = null;
Session["InventoryMissing"] = null;
var userSession = Session.GetSessionUserInfo();
if (userSession != null)
{
List<inventoryproductsviewmodel> products = db.Products.Where(p => !p.IsDeleted && p.CompanyId == userSession.CompanyId && (categoryId == 0 || p.SubCategory.CategoryId == categoryId)).Select(p => new InventoryProductsViewModel { Id = p.Id, Title = p.Title, SubCategory = p.SubCategory.Title, IMEINumber = p.IMEINumber, Balance = (p.PurchasedQuantity - p.SoldQuantity) }).ToList();
Session["Products"] = products;
if (Session["InventoryMissing"] == null)
Session["InventoryMissing"] = new List<inventorymissing>();
return PartialView("ProductsPartialView", products);
}
else
{
return Redirect("~/Error/Error");
}
}
===================================
PartialView
@model List<viewmodel.inventoryproductsviewmodel>
<table>
<tr>
<th>
@Html.DisplayNameFor(Model[0].Title)
</th>
<th>
@Html.DisplayNameFor(Model[0].SubCategory)
</th>
<th>
@Html.Label("Balance")
</th>
<th>
@Html.Label("Count")
</th>
<th>
@Html.Label("Difference")
</th>
<th>
@Html.Label("IMEI Number")
</th>
</tr>
@for (int i = 0; i < Model.Count(); i++ )
{
<tr id="@Model[i].Id">
<td>
@Html.Hidden(Model[i].subId)
@Html.DisplayFor(Model[i].Title)
</td>
<td>
@Html.DisplayFor(Model[i].SubCategory)
</td>
<td class="balance">
@Html.DisplayFor(Model[i].Balance)
</td>
<td>
@Html.EditorFor(Model[i].InventoryCount)
</td>
<td class="difference">
0
</td>
<td>
@Html.DisplayFor(modelItem =>Model[i].IMEINumber)
</td>
/pre>tr>
}</tr></table>