2 Replies - 1167 Views - Last Post: 05 August 2013 - 07:38 AM Rate Topic: -----

#1 IrishCoder  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 37
  • Joined: 07-April 10

Details Page with two id's being passed.

Posted 05 August 2013 - 07:19 AM

Hi all, need some advice as to why my details page is not showing for the 2 id's that I am passing. Here is my code as follows:

Controller:

public ActionResult Details(int id1 = 0, int id2 = 0)
        {
            string test = "SELECT SalesLT.Product.ProductID, SalesLT.ProductDescription.ProductDescriptionID, SalesLT.Product.Name, SalesLT.Product.ListPrice, LEFT(SalesLT.ProductDescription.Description, 20) as Descrption FROM SalesLT.Product, SalesLT.ProductDescription, SalesLT.ProductModelProductDescription WHERE SalesLT.Product.ProductModelID = SalesLT.ProductModelProductDescription.ProductModelID AND SalesLT.ProductModelProductDescription.ProductDescriptionID = SalesLT.ProductDescription.ProductDescriptionID AND SalesLT.Product.ProductID =" + id1 + "AND SalesLT.ProductDescription.ProductDescriptionID =" + id2;
            var viewModel = db.Database.SqlQuery<ProdList>(test).ToList();
            if (viewModel == null)
            {
                return HttpNotFound();
            }
            return View(viewModel);
            
        }


ViewModel:

public class ProdList
    {
        public int ProductID { get; set; }
        public int ProductDescriptionID { get; set; }
        public string Name { get; set; }
        public decimal ListPrice { get; set; }
        public string Description { get; set; }
    }


Details View:

@model AW_Internet.Models.ProdList

@{
    ViewBag.Title = "Details";
}

<h2>Prod Details</h2>

<div class="displayField">
    @Html.DisplayFor(model => model.ProductID)
</div>
<div class="displayField">
    @Html.DisplayFor(model => model.ProductDescriptionID)
</div>
<div class="displayField">
    @Html.DisplayFor(model => model.Name)
</div>
<div class="displayField">
    @Html.DisplayFor(model => model.ListPrice)
</div>
<div class="displayField">
    @Html.DisplayFor(model => model.Description)
</div>

<p>
    @Html.ActionLink("Back to List", "Index")
</p>



Oh and here is a snippet of my Index view where the 2 id's are being passed:

<td>
            @Html.ActionLink("Details", "Details", new { id1 = item.ProductID, id2 = item.ProductDescriptionID })
        </td>

This post has been edited by IrishCoder: 05 August 2013 - 07:21 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Details Page with two id's being passed.

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3333
  • View blog
  • Posts: 11,297
  • Joined: 12-December 12

Re: Details Page with two id's being passed.

Posted 05 August 2013 - 07:25 AM

"AND SalesLT.

You have no space between the word AND and the previous id.

Doesn't it give you any errors? I don't use ASP but I would assume there should be an error-log somewhere, even if it's just in the Output window.

This post has been edited by andrewsw: 05 August 2013 - 07:27 AM

Was This Post Helpful? 0
  • +
  • -

#3 IrishCoder  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 37
  • Joined: 07-April 10

Re: Details Page with two id's being passed.

Posted 05 August 2013 - 07:38 AM

View Postandrewsw, on 05 August 2013 - 07:25 AM, said:

"AND SalesLT.

You have no space between the word AND and the previous id.

Doesn't it give you any errors? I don't use ASP but I would assume there should be an error-log somewhere, even if it's just in the Output window.


Thanks I just corrected that, however that doesn't seem to fix the problem. When hovering mouse over the Details link I can see it is picking up the 2 id's necessary so that is all fine. However the error I am getting is the following :

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[AW_Internet.Models.ProdList]', but this dictionary requires a model item of type 'AW_Internet.Models.ProdList'.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1