【问题标题】:Partial Views with different model in Asp.net MVCAsp.net MVC 中不同模型的局部视图
【发布时间】:2017-03-24 13:27:00
【问题描述】:

我有两个类如下

Model:-  

     public class RegisterViewModel
        {
             public string Email { get; set; }     
             public AddressPropertyVM AddressProperty { get; set; }
        }

        public class AddressPropertyVM
        {
             public string StreetNo { get; set; }     
        }
Main Form
@model Application.Models.RegisterViewModel
{
    @Html.TextBoxFor(m => m.Email)
    @Html.TextBoxFor(m => m.FirstName)

    @Html.Partial("_AddressPropertyPartial",Model.AddressProperty)

    <button type="submit">Register</button>

}

Partial View Form
@model Application.Models.AddressPropertyVM
{
    @Html.TextBoxFor(m => m.StreetNo)

}

我正在创建 asp.net mvc 应用程序。

我已经为 AddressPropertyVM 创建了一个局部视图。

但我们当时发布了表单(主表单),AddressProperty 的数据为空。

【问题讨论】:

  • 你能显示视图吗?
  • 我的看法是这样的

标签: asp.net-mvc-4 partial-views asp.net-mvc-partialview


【解决方案1】:

根据我的理解,您希望在一个部分视图中使用多个页面,我的意思是在多个页面中多次使用一个页面。

阅读此article 并了解其工作原理。

按照下面的文章更改您的代码。

@Html.Partial("_AddressPropertyPartial",Model.AddressProperty)

@Html.Partial("_AddressPropertyPartial", Model.AddressProperty,  new ViewDataDictionary()   {     TemplateInfo = new TemplateInfo()       { HtmlFieldPrefix = "AddressProperty" } }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-15
    • 2010-12-06
    • 1970-01-01
    • 2013-06-14
    • 2015-06-21
    • 1970-01-01
    相关资源
    最近更新 更多