夥計們我試圖使用單個視圖的多個模型。如何將單個視圖綁定多個模型?
但我找不到解決方案如何實現它。
我想使用單過去,另一個在另一部分之一查看數據..
我用下面的代碼..
這是一個觀點
@Html.Partial("Sidebar")
這是另一種觀點
<!-- start content -->
<div id="content">
<div class="post">
<h1 class="title">
Add New Post
</h1>
<p></p>
<div class="entry">
@using (Html.BeginForm())
{
<div>
<div style="display:inline;">
<div style="display: inline; float: left;">
@Html.Label("lblcategory", "Category", new { style = "Width:100px; float: left;" })
<div style="width: 150px; height: 60px; overflow-y: scroll; display: inline; float: left;">
@for (int i = 0; i < (int)TempData["Rows"]; i++)
{
for (int j = 0; j < (int)TempData["Cols"]; j++)
{
<input id="Checkbox + @i" name = "Category" type="checkbox" style="width:50px;" value="@TempData["[" + i.ToString() + "][" + j.ToString() + "]"]"/>
@TempData["[" + i.ToString() + "][" + j.ToString() + "]"]
}
}
@*@Html.LabelFor(model => model.CategoryName)*@
</div>
<div style="float:right;">
<label id="lblcategoryrequired" style="color:Red">@Html.ValidationMessageFor(model => model.CategoryName)</label>
</div>
</div>
</div>
<div>
<p style="display: inline; float: left;">
@Html.Label("lblsubjet", "Subject", new { style = "Width:100px; float: left;" })
@*@Html.TextBox("txtsubject", "", new { style = "Width:700px;" })*@
@Html.TextBoxFor(model => model.PostSubject, new { style = "Width:400px; maxlength=400;" })
<label id="lblsubjectrequired" style="color:Red">@Html.ValidationMessageFor(model => model.PostSubject)</label>
</p>
</div>
<div>
<p style="display: inline; float: left;">
@Html.Label("lblcontent", "Content", new { style = "Width:100px; float: left; Vertical-align:top;" })
@*@Html.TextArea("txtcontent","", new { style = "Width:700px; height:200px; maxlength=700;" })*@
@Html.TextAreaFor(model => model.PostContent, new { style = "Width:400px; height:200px; maxlength=400;" })
</p>
</div>
<div>
<p style="display: inline; float: left;">
@Html.Label("lblblank", "a", new { style = "Width:100px; float: left; Color:#372412" })
<input type="submit" value="Add" id="btnadd" style="width: 100px;" class="button" />
    
<a id="Cancel" href="~/Home/Home"> <input type="button" value="Cancel" id="btncancel" class="button" style="width: 100px;" /></a>
</p>
</div>
</div>
@Html.ValidationSummary(true)
}
</div>
</div>
</div>
</div>
你可以有既有車型視圖模型,你可以綁定,以你的觀點 –