2 Replies - 2741 Views - Last Post: 25 May 2011 - 12:54 AM

#1 erburrell  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 145
  • Joined: 22-December 09

Why is item NULL?

Posted 12 January 2011 - 11:36 AM

Hi all,

I am working on an MVC website, and am having a problem with passing data to my controller. My view has two partial views, and the one that is giving me a headache is below:

CableSummaryPartialView:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<MagnoliaWeb.DAO.CableSummary>>" %>

    <p>
        <%= Html.ActionLink("Create New", "Create") %>
    </p>
    <table>
        <tr>
            <th></th>
            <th>
                Id
            </th>
            <th>
                CableId
            </th>
            <th>
                System
            </th>
        </tr>

    <% foreach (var item in ViewData["cablesummary"] as IEnumerable<MagnoliaWeb.DAO.CableSummary>) { %>
    
        <tr>
            <td>
                <%= Html.ActionLink("Details", "Details", new { item.Id })%>
            </td>
            <td>
                <%= Html.Encode(item.Id) %>
            </td>
            <td>
                <%= Html.Encode(item.CableId) %>
            </td>
            <td>
                <%= Html.Encode(item.System) %>
            </td>
        </tr>
    
    <% } %>

    </table>


My ActionResult in my controller looks like this:
public ActionResult Details(int cableId)
        {
            ViewData["cablesummary"] = repository.GetCableListSummary();

            ViewData["cabledetails"] = repository.GetCableDetails(cableId);
            ViewData["cableterminations"] = repository.GetCableTermination(cableId);
            ViewData["cableroute"] = repository.GetCableRoutes(cableId);
            
            return View("Index");
        }


The problem appears to be that my View is passing my controller a null value. I have tried the code shown here, as well as trying to pass item as a whole and receiving it with a variable of the appropriate class.

Just so everyone knows, I have watched the value while debugging, and it is indeed passing a null...

Any ideas?

Thanks!

Ed

This post has been edited by erburrell: 12 January 2011 - 11:38 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Why is item NULL?

#2 Asusultra  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 39
  • Joined: 24-March 09

Re: Why is item NULL?

Posted 24 May 2011 - 09:52 PM

"passing a null" as in here Details(int cableId or here ViewData["cablesummary"] = repository.GetCableListSummary();
or here (var item in ViewData["cablesummary"] as IEnumerable<MagnoliaWeb.DAO.CableSummary>)?

Also,

What causes your partial view to display? is it the "Details" or the "Index" action? if it isn't "Details" can you post the Action?

This post has been edited by Asusultra: 24 May 2011 - 09:59 PM

Was This Post Helpful? 0
  • +
  • -

#3 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Why is item NULL?

Posted 25 May 2011 - 12:54 AM

I'd say problem is here:

<%= Html.ActionLink("Details", "Details", new { item.Id })%>


update it to:

<%= Html.ActionLink("Details", "Details", new { cableId = item.Id })%>


Hope this helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1