ASP。NET MVC 1 . .Ajax。BeginForm Html.BeginForm之内。如何在不停止和启动Html表单的情况下发布?

时间:2021-07-31 03:43:19

For example..

例如. .

<% using (Html.BeginForm()) { %>
<%= html.textBox(Model.IwantThisField)%>

<%using (Ajax.BeginForm("ActionName", new AjaxOptions { fancy ajax options })) %>
   <%{%>
     <label for="stringVar">This is sent to Action</label>
     <input type ="submit" id="button" />
   <%}%>

<%= html.textBox(Model.IalsoWantThisField) %>
<input type="submit" id="mainBtn"/> 
<% } %

>

Any more information needed I will provide. This has had me stumped on a Fridat afternoon which is not at all fun. Any help much appreciated!

我将提供更多的信息。这让我在一个毫无乐趣的下午被难住了。任何帮助表示感谢!

1 个解决方案

#1


2  

You can't nest a form within a form. What are you trying to accomplish? You could remove your Ajax.BeginForm, change the input from type submit to button, then capture the button click with JQuery and make your ajax request with $.post.

不能将窗体嵌套在窗体中。你想要完成什么?可以删除Ajax。从submit到button,更改输入,然后用JQuery捕捉按钮,并以$.post的方式发出ajax请求。

<% using (Html.BeginForm()) { %>
<%= html.textBox(Model.IwantThisField)%>

     <label for="stringVar">This is sent to Action</label>
     <input type ="buttom" id="button" />


<%= html.textBox(Model.IalsoWantThisField) %>
<input type="submit" id="mainBtn"/> 
<% } %

<script type="text/javascript">
$(function()
{
    $('#button').click(function(){
        var value = $('#stringVar').val();
        var data = {stringVar: value};
        $.post('Your action URL',data,function(data){
             //On complete Ajax request javascript.
        });
        return false;
    });
});
</script>

#1


2  

You can't nest a form within a form. What are you trying to accomplish? You could remove your Ajax.BeginForm, change the input from type submit to button, then capture the button click with JQuery and make your ajax request with $.post.

不能将窗体嵌套在窗体中。你想要完成什么?可以删除Ajax。从submit到button,更改输入,然后用JQuery捕捉按钮,并以$.post的方式发出ajax请求。

<% using (Html.BeginForm()) { %>
<%= html.textBox(Model.IwantThisField)%>

     <label for="stringVar">This is sent to Action</label>
     <input type ="buttom" id="button" />


<%= html.textBox(Model.IalsoWantThisField) %>
<input type="submit" id="mainBtn"/> 
<% } %

<script type="text/javascript">
$(function()
{
    $('#button').click(function(){
        var value = $('#stringVar').val();
        var data = {stringVar: value};
        $.post('Your action URL',data,function(data){
             //On complete Ajax request javascript.
        });
        return false;
    });
});
</script>