简单回发的 MVC 问题
这里有点奇怪: 下面的 razor 语法渲染了一个简单的 html,底部有一个提交按钮。 当我点击该按钮时,我希望执行回发,但出于某种原因它没有......任何想法?
哦,顺便说一句,这是视图的完整代码...
@model FLM.PRL.EComms.Models.ReplySMS
@using (Html.BeginForm("Reply", "SMS", FormMethod.Post)) {
<h2>Follow Up</h2>
@Html.ValidationSummary(true)
@Html.HiddenFor(model => Model.From)
@Html.HiddenFor(model => Model.To)
<div class="editor-label">Reply</div>
<div class="editor-field">
@Html.EditorFor(model => Model.Message)
@Html.ValidationMessageFor(model => Model.Message)
</div>
<input type="submit" value="Reply" />
<br />
}
编辑:由此视图生成的结果标记...
<form action="/SMS/Reply" method="post">
<h2>Follow Up</h2>
<input data-val="true" data-val-required="The From field is required." id="From" name="From" type="hidden" value="xxxxxxxx" /><input data-val="true" data-val-required="The To field is required." id="To" name="To" type="hidden" value="xxxxxxx" /> <div class="editor-label">Reply</div>
<div class="editor-field">
<textarea class="text-box multi-line" id="Message" name="Message">
</textarea>
<span class="field-validation-valid" data-valmsg-for="Message" data-valmsg-replace="true"></span>
</div>
<input id="submitReply" type="submit" value="Reply" />
<br />
</form>
Bit of an odd one here:
The following razor syntax renders a nce simple html from with a submit button inside the bottom of it.
When i hit that button i would expect a postback to performed but for reason it dosn't ... any ideas??
Oh by the way this is the entire code for the view ...
@model FLM.PRL.EComms.Models.ReplySMS
@using (Html.BeginForm("Reply", "SMS", FormMethod.Post)) {
<h2>Follow Up</h2>
@Html.ValidationSummary(true)
@Html.HiddenFor(model => Model.From)
@Html.HiddenFor(model => Model.To)
<div class="editor-label">Reply</div>
<div class="editor-field">
@Html.EditorFor(model => Model.Message)
@Html.ValidationMessageFor(model => Model.Message)
</div>
<input type="submit" value="Reply" />
<br />
}
EDIT: Resulting markup generated by this view ...
<form action="/SMS/Reply" method="post">
<h2>Follow Up</h2>
<input data-val="true" data-val-required="The From field is required." id="From" name="From" type="hidden" value="xxxxxxxx" /><input data-val="true" data-val-required="The To field is required." id="To" name="To" type="hidden" value="xxxxxxx" /> <div class="editor-label">Reply</div>
<div class="editor-field">
<textarea class="text-box multi-line" id="Message" name="Message">
</textarea>
<span class="field-validation-valid" data-valmsg-for="Message" data-valmsg-replace="true"></span>
</div>
<input id="submitReply" type="submit" value="Reply" />
<br />
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不提交此表单的唯一原因是脚本干扰了该过程。也许是验证脚本。
我注意到消息字段是必需的。您是否为该字段提供了值?您没有任何验证错误消息吗?
如果验证正常,我建议有选择地从页面中删除所有脚本,看看会发生什么。如果删除脚本后您的表单可以正常工作,您就知道这是问题的根源。
The only reason for this form not to be submitted are scripts interfering with the process. Maybe the validation scripts.
I noted that the Message field is required. Did you provided a value to this field? Don't you have any validation error message?
In the case validation is fine, I suggest removing selectively all the scripts from the page and see what happens. If removing a script results in your form working, you know it is the source of the problem.
我想通了...这是隐藏字段...它们是必需的,但在回发期间由服务器填充,因此自动验证会在服务器能够填充字段之前阻止回发客户端...
解决方案:
不要向 MVC 表单添加空的必填字段或关闭验证(不是一个好主意)
I figured it out ... it's the hidden fields ... they are required but populated by the server during the postback so the auto validation prevents the postback client side before the server is able to populate the fields ...
solution:
Don't add empty required fields to an MVC form or turn off validation (not a good idea)