在页面中我只有三个复选框,客户端应该在点击提交按钮之前至少选择一个:
控制器:
[HttpPost]
public ActionResult Client(OrderItems model)
{
if (bValidated){
//Code here
}
else
{
model.itemChoosed = false;
return View("Client", model);
}
View Client:
@model WebApp.Models.OrderItems
@using (Html.BeginForm("Client", "Home", FormMethod.Post, new { @class = "form-group", role = "form" }))
{
@Html.AntiForgeryToken();
<h2>Client</h2>
@Html.Partial("SentMessage")
<div>
<div>
<h3>Item 1</h3>
<label>@Html.CheckBoxFor(model => model.CLInfo.Item1) Item 1</label>
</div>
<div>
<h3>Item 2</h3>
<label>@Html.CheckBoxFor(model => model.CLInfo.Item2) Item 2</label>
</div>
<div>
<h3>Item 3</h3>
<label>@Html.CheckBoxFor(model => model.CLInfo.Item3) Item 3</label>
</div>
</div>
<div class="row">
<input type="submit" name="action:Client" id="btnClient" class="btn btn-primary flat btn-large pull-right" value="Client" />
</div>
}
在我选择将条件放入Partail视图后: 部分查看SentMessage:
@model WebApp.Models.OrderItems
@if (!model.itemChoosed)
{
<div>You must choose at least one item</div>
}
我收到错误消息:
视图&#39;客户&#39;或者找不到它的主人,或者没有视图引擎支持搜索到的位置。搜索了以下位置: 〜/浏览/首页/ Client.aspx .. 〜/浏览/首页/ Client.cshtml ..
但Home / Client.cshtml existe,因为它是视图
由于