Sangamesh
Sangamesh

Reputation: 13

Data is not loading into Model Project

Please help to find solution, data is not being loaded into model object.

Controller code:

public ActionResult ProductDetails(string ItemId)
{
    return PartialView();
}
 
[HttpPost]
public ActionResult Index(string ItemId)
{
    listOfShoppingCartModels = GetDetails(ItemId);
    return PartialView("ProductDetails", listOfShoppingCartModels);
}

ProductDetails view:

<div class="container">
   <h2 class="text-center">Product List</h2>
   @foreach (var item in Model)
   {
    <div class="col-md-4" style="border: 2px solid black">
    <div style="text-align: center; border-bottom: 2px solid maroon">
      <h3>@item.ItemName</h3>
  </div>
  <div>
     <div class="col-md-8">
         <img src="@Url.Content(@item.ImagePath)" width="150px" height="150px" />
     </div>
      <div class="col-md-4" style="text-align: left">
         <b>@item.Description</b>
      </div>
</div>

Shopping view model:

public class ShoppingViewModel
{
    public Guid ItemId { get; set; }
    public string ItemName { get; set; }
    public decimal ItemPrice { get; set; }
    public string ImagePath { get; set; }
    public string Description { get; set; }
    public string ItemCode { get; set; }
    public string Category { get; set; }
}

Error:

Server Error in '/' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 12:
Line 13: Product List
Line 14: @foreach (var item in Model)
Line 15: {
Line 16:

Source File: C:\Users\Sangamesh.Rawoor\Downloads\WebAppECart-master (2) (1)\WebAppECart-master\WebAppECart-master\WebAppECartDemo\Views\Shopping\ProductDetails.cshtml Line: 14

Upvotes: 1

Views: 68

Answers (1)

asmak9
asmak9

Reputation: 274

Crate Index HTTPGET action method in order to load your data.

Upvotes: 0

Related Questions