Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Can posted input values on onbegin of ajax.beginform be modified? I have to modify values of some of the input fields after the form is submitted. But even if I change the values through js, at server side in request.form I am getting the old values which were set initially at the time of form submit. How to get the modified values in request.form?

The code block is as follows:

<% using(Ajax.BeginForm("action", "controller",
     new AjaxOptions{onbegin="funBegin",oncomplete="funComplete"})){ 
%>

<input type="text" id="txtName" name="txtName" value="gaurav"/>
<input type="text" name="txtAge" value="26"/>
<input type="submit" value="click here" />

<% } %>

<script type="text/javascript">
    function funBegin() {
        $("#txtName").val("gaurav pandey");
    }
    function funBegin(result) {
        $("#divParent").html(result.get_data());
    }
</script>

Now when I try to get request.form["txtname"] at server side, I am getting "gaurav" instead of "gaurav pandey".

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
759 views
Welcome To Ask or Share your Answers For Others

1 Answer

I didn't feel like going outside of MVC's form submission handling so I solved this differently. Just bind to the form's submit button's click handler. Do your input value fiddling there. The onclick is fired before MVC's form serialization. The onclick also gets called even if the form is submitted by the user hitting enter.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...