我有一个带有2个按钮的表单,它们处于相同的动作,但是当按下Confirm
按钮时,它不需要验证,只需按一下并进入该动作,而当{{ 1}}按钮,则必须填写文本区域Reject
。
这是我的观点:
Comment
这是动作
@if (Model.signingFlowViewModel.signingFlows.Count(s => s.SigningUser == User.Identity.Name && s.Status == "1") > 0)
{
using (Html.BeginForm("OvertimeSigningAsync", "Signing", FormMethod.Post,
new { onsubmit = "return confirm('Do you really want to submit the form?');" }))
{
<div class="row" style="margin-top:10px;">
<div class="col-sm-3">
<div class="form-group">
<input type="submit"
name="Sign" value="Confirm"
class="form-control btn btn-primary"
style="margin-bottom: 5px" />
<br>
<input type="submit"
name="Sign" value="Reject"
class="form-control btn btn-danger"/>
</div>
</div>
<div class="col-sm-9">
<div class="form-group">
@Html.TextBoxFor(m => m.DocNo, new { @class = "hidden" })
@Html.TextBoxFor(m => m.FlowNo, new { @class = "hidden" })
@Html.TextBoxFor(m => m.Plant, new { @class = "hidden" })
@Html.TextAreaFor(m => m.Comment, new { @class = "form-control", @required = "required" })
@Html.TextBoxFor(m => m.NewDocNo, new { @class = "hidden" })
</div>
</div>
</div>
}
}
现在,当按下按钮public async Task<ActionResult> OvertimeSigningAsync([Bind(Include = "Plant,FlowNo,DocNo,Comment,NewDocNo")]
OvertimeSigningViewModel overtimeSigningViewModel, string Sign)
{
bool result = false;
if (ModelState.IsValid && !String.IsNullOrWhiteSpace(Sign))
{
result = eISRepository.EditPurchaseRequest(
overtimeSigningViewModel.Plant,
overtimeSigningViewModel.FlowNo,
overtimeSigningViewModel.DocNo,
User.Identity.Name, Sign,
overtimeSigningViewModel.Comment,
overtimeSigningViewModel.NewDocNo);
}
}
时,如何验证文本区域。
我只是MVC的新手,所以请帮忙。非常感谢
答案 0 :(得分:0)
我已经找到了,只需在确认按钮上添加属性const PostTitle = ({ record }) => {
return <span>Post {record ? `"${record.title}"` : ''}</span>;
};
export const PostShow = (props) => (
<Show title={<PostTitle />} {...props}>
...
</Show>
);
,就可以了
formnovalidate