Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
 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; }
    ///// <summary>
    ///// categoryId
    ///// </summary>
    //public long CatId { get; set; }
    /// <summary>
    /// subCategory id
    /// </summary>
    public long subId { get; set; }
   // public List<category> lstCategory { get; set; }
}

==============================
Controller Action
C#
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(); //&& (subCategoryId == 0 || p.SubCategoryId == subCategoryId)

            Session["Products"] = products;

            if (Session["InventoryMissing"] == null)
                Session["InventoryMissing"] = new List<inventorymissing>(); 

            //if (products.Count() > 0)
            //{
            //    ViewBag.Category = products[0].SubCategory.CategoryId;
            //}
            //else
            //{
            //    ViewBag.Category = 0;
            //}

            return PartialView("ProductsPartialView", products);
        }

        else
        {
            return Redirect("~/Error/Error");

        }
    }

===================================
PartialView
HTML
@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>
Posted
Updated 18-Mar-15 0:57am
v3

1 solution

Html Helpers For Model were used which was creating problem. Correct Helpers are as follow.

<pre lang="HTML">@model List<hitechpos.viewmodel.inventoryproductsviewmodel>

<table class=" table table-striped table-advance table-hover">
<tr>
    <th>
        @Html.Label("Product Name")
    </th>
    <th>
        @Html.Label("SubCategory Name")
    </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.DisplayFor(modelItem => item.Id)
        </td>*@
        <td>
            @Html.Hidden(Model[i].subId.ToString())
            @Html.Label(Model[i].Title)
        </td>
        <td>
            @Html.Label(Model[i].SubCategory)
        </td>
        <td class="balance">
            @Html.Label(Model[i].Balance.ToString())
        </td>
        <td>
            @Html.Editor(Model[i].InventoryCount.ToString())
        </td>
        <td class="difference">
            @Html.Label(Model[i].Difference.ToString())
        </td>
        <td>
            if(Model[i].IMEINumber == null)
                {
                    @Html.Label("")
            }
            else
                { 
                @Html.Label(Model[i].IMEINumber)
            }
        </td>
    </tr>
}</table></hitechpos.viewmodel.inventoryproductsviewmodel>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900