[英]Asp.net with MVC Partial view and models
我的應用程序中總共有5個模型。 我有一個帶有Kendo面板欄的“ index.cshtml”頁面。 我在每個劍道面板欄中提到了每個模型。 因此,我現在不想將所有這5個模型分組為一個單獨的類文件,例如“ Mainmodel”。 我也應該只將此模型傳遞給控制器。 控制器,該控制器依次將此模型分為5個模型。
public class MainModel
{
public Model1 firstmodel{get; set;}
public Model2 secondmodel{get; set;}
public Model3 thirdmodel{get; set;}
public Model4 fourthmodel{get; set;}
public Model5 fifthtmodel{get; set;}
}
我想在視圖中使用此“主要”模型。 這個怎么做。??
public class Model1
{
public string name {get; set;}
}
public class Model2
{
public string DOB{get; set;}
}
//index.cshtml
@model mvc.Models.MainModel
@using (Html.Beginform("SaveData","Home"))
{
@html.kendo().panelbar()
.items()
{
items.add()
.content(@html.textboxfor(x=> x. /// here I did not get any properties that I have created name,DOB
}
//My controller
[httppost]
public Actionresult SaveData(MainModel mainmodel)
{
retun view("Index",mainmodel);
}
如何在MainModel中的index.cshtml中使用此屬性?
我所做的是將視圖分為局部視圖,因此主視圖將接受(MainModel)作為其模型,然后局部視圖將分別從(MainModel)內部接受不同的模型,例如:
//index.cshtml
@model mvc.Models.MainModel
@using (Html.Beginform("SaveData","Home"))
{
@html.kendo().panelbar()
.items()
{
items.add()
.content(@Html.Partial("firstmodelView", Model.firstmodel))
}
//firstmodelView.cshtml
@model Model1
@Html.TextBoxFor(x=> x.name)
//主要模型
//index.cshtml
@model mvc.Models.MainModel
@using (Html.Beginform("SaveData","Home"))
{
@html.kendo().panelbar()
.items()
{
items.add()
.content(@Html.Partial("firstmodelView", Model))
}
//在部分頁面中
@model mvc.Models.MainModel
@Html.TextBoxFor(x=> x.Firstmodel.Name)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.