开发者

MVC Problem with simple Postback

开发者 https://www.devze.com 2023-03-31 00:12 出处:网络
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.

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>


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.


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号