English 中文(简体)
ASP.net MVC2 强烈分类观点之间的数据
原标题:ASP.net MVC2 Passing data between strongly typed views

我的以下MVC2认为,这种观点被严格归类为“观点”,“观点”包含一份从一个表格中得出的数值清单,我认为,从第二个表格中可以看出一个数值。

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"   Inherits="System.Web.Mvc.ViewPage<CustomerDatabase.WebUI.Models.CustomerSitesListViewModel>    " %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Customer Sites
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% foreach (var customerSite in Model.CustomerSites) { %>
<% Html.RenderPartial("CustomerSiteSummary", customerSite); %>
<%} %>
</asp:Content>

This is the viewmodel, notice i am including a Customer member in the viewmodel as i want to display the customer name in addition to the list of customer sites

namespace CustomerDatabase.WebUI.Models
{
public class CustomerSitesListViewModel
{
    public IList<CustomerSite> CustomerSites { get; set; }
    public PagingInfo PagingInfo { get; set; }
    public Customer customer { get; set; }
}
}

This is my controller code for the view

 public ViewResult List([DefaultValue(1)] int page)
    {
        var customerSitesToShow = customerSiteRepository.CustomerSites;
        var viewModel = new CustomerSitesListViewModel
        {
            CustomerSites = customerSitesToShow.Skip((page - 1) *   PageSize).Take(PageSize).ToList(),
            PagingInfo = new PagingInfo
            {
                CurrentPage = page,
                ItemsPerPage = PageSize,
                TotalItems = customerSitesToShow.Count()
            }
        };

        return View(viewModel);  //Passed to view as ViewData.Model (or simply model)
    }

This is my partial view that renders the list,

<%@ Control Language="C#"    Inherits="System.Web.Mvc.ViewUserControl<CustomerDatabase.Domain.Entities.CustomerSite>" %>
<div class="item">
<div class="customer-list-item">
<h2><%:Model.customer.CustomerName%></h2>
<%: Model.AddressLine1 %> 
<%: Model.AddressLine2%>

虽然在座各位允许我从看看看看看客户物体。

<h2><%:Model.customer.CustomerName%></h2>

一种错误在浏览时被推翻,

Object reference not set to an instance of an object. Source Error:

Line 7:   <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
Line 8:   <% foreach (var customerSite in Model.CustomerSites) { %>
Line 9:   <%:Model.customer.CustomerName%>
Line 10:  <% Html.RenderPartial("CustomerSiteSummary", customerSite); %>
Line 11:  <%} 

我认为,这一错误是因为有人认为,要列出一个名单,即试图将观点成员改为观点成员。

 public IList<Customer> {get; set;}

但这也不可行。

任何人能否建议一种办法,即能够做到这一点,或就哪里发生错失行为提出任何建议? 这个问题在数小时后无法解决,或者在互联网上进行研究?

最佳回答

它认为,像一种模式性质一样,没有初步形成。 如果你在这条线上添加一个断点,并核对变量Im ,那么你就会发现1个是<代码>null。

问题回答

暂无回答




相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签