English 中文(简体)
ASP MVC3中的一种观点
原标题:Repeating view within a view in ASP MVC3

如果我有详细的重复布局,我只想一劳永逸地界定一些箱子,但是这些箱子的内容在从电网到电网之间(而不是在电网内)会有所不同,例如,一页有产品提要网,另一页有一类介绍网。 执行MVC3的最敏感模式是什么?

问题回答

你可以使用显示模板。 例如,在您看来,界定了一种类型为<代码>的财产。 缩略语

public class MyViewModel
{
    public IEnumerable<SomeViewModel> Models { get; set; }
}

并且认为使用显示器的助手:

@model MyViewModel
@Html.DisplayFor(x => x.Models)

然后界定一个海关显示模板,该模板将自动提供给《示范公约》收集的每个要素(<>~/Views/共享/DisplayTemplates/SomeViewModel.cshtml):

@model SomeViewModel
<div>
    @Html.DisplayFor(x => x.SomeProperty)
    ...
</div>

模拟助手按公约开展工作。 缺席,将首先在<代码>~/Views/CurrentController/DisplayTemplate上查阅。 <代码>~/View/joint/DisplayTemplates 模板的夹,名称与收集财产的类型相同(< 代码>)。 SomeViewModel.cshtml 。

你可以把重复部分观点推向一个部分。 然后,这种部分观点可在任何地方重复使用。

5. 仓库主计长采取的行动:

  [ChildActionOnly]
    public ActionResult GenreMenu()
    {
        var genres = storeDB.Genres.ToList();

        return PartialView(genres);
    }

在观点中,这将重复部分观点三倍:

@for (int i = 0; i < 3; i++)
{
 Html.RenderAction("GenreMenu", "Store");
}




相关问题
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 (...

热门标签