我有一个呈现两个部分视图的主视图。主视图包含表单中的两个部分视图。每个部分视图还包含表单。所有 3 个视图共享相同的视图模型。我想要做的是用主视图封装来自所有视图的数据,并用部分视图运行特定的控制器操作结果。
我想知道这是否可能。调试时,我看到我的内容总是发布到主视图表单的 HTTPPost。我有相应的每个表单的提交按钮。对不起,代码发布,它的出现都分裂了。
主视图:
@using (Html.BeginForm("Main", "Registration", FormMethod.Post,
new { @class="mainform" }))
{
<form>
<fieldset>
<div id ="option1" class="conglomerate">
@Html.Partial("_GetBusiness")
</div>
<div id ="option2" class="dealership">
@Html.Partial("_GetLocation")
</div>
<button type="submit" value="Create" class="buttonBlue" id="">
<span>Create a new dealer</span>
</button>
</fieldset>
</form>
部分 1
@using (Html.BeginForm("CreateBusiness", "Business", FormMethod.Post,
new { @class="buisinessform" }))
{
<form>
<div class="editor-field">
@Html.DropDownListFor(m =>m.BusinessId, new SelectList(Model.Businesses,
"BusinessId", "BusinessName"), "")
</div>
<label>Your company not listed? Register yours below:</label>
<div class="editor-label">
@Html.LabelFor(model => model.BusinessName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.BusinessName)
@Html.ValidationMessageFor(model => model.BusinessName)
</div>
<button type="Button" value="" class="buttonBlue"id="TestSubmit">
<span>Add Dealer</span>
</button>
<div class ="confirm">
<button type="submit" value="Create" class="buttonBlue" id="">
<span>Click here to confirm dealer addition</span>
</button>
</div>
</form>
}