Как отправить форму, которая находится внутри другой формы в asp.net mvc

0

У меня есть форма Html, в которой есть кнопка отправки, и внутри формы у меня есть несколько разделов, которые необходимо отправить отдельно. Поскольку Html не поддерживает вложенные формы, как я могу это сделать? А также каждый раздел должен быть проверен перед отправкой.

<%  using (Html.BeginForm("actionName", "controllerName", FormMethod.Post))
        { %>
<form id="frmHomeContact" method="post"  >
                       -- a partial view is rendered here
                       <div class="grid-2-12">

                            <input style="width: 100%;" type="button" title="save" value="save" />
                        </div>
                      </form>

<%}%>

Дайте мне знать, если вопрос непонятен.

  • 0
    jQuery.post() =)
Теги:
asp.net-mvc

2 ответа

1
$('#frmHomeContact').on('submit', function(){
    var $this = $(this); // catch a reference to the form
    $.ajax({
        url: '/', //this should probably be the path to your controller
        type: 'POST',
        data: $this.serialize(), //name=George&msg=hello..etc <--note $this not $(this)
        success: function(){
            console.log('Successful submission.');
        }
    });
    return false; //submitting the form will no longer cause the browser to refresh.
});
  • 0
    Должен ли тип кнопки быть «отправить»? Я пытался, но это не работает.
  • 0
    Какая у вас версия jQuery? для этого требуется 1.7, используйте $('#frmHomeContact').submit( если вы используете версию ниже 1.7
Показать ещё 2 комментария
0

Ваш html-код выглядит так:

<%  using (Html.BeginForm("actionName", "controllerName", FormMethod.Post),new { id = "frmHomeContact" })
        { %>
<form  method="post"  >
                       -- a partial view is rendered here
                       <div class="grid-2-12">

                            <input style="width: 100%;" type="button" title="save" value="save" />
                        </div>
                      </form>
<%}%>
<script type="text/javascript">
    $("#frmHomeContact").submit(function() {
    var $this = $(this); // catch a reference to the form
        $.ajax({
            url: '/', //this should probably be the path to your controller
            type: 'POST',
            data: $this.serialize(), //name=George&msg=hello..etc <--note $this not $(this)
            success: function(){
                alert('Successful submission.');
            }
        });
        return false; //submitting the form will no longer cause the browser to refresh.
    });
</script>

Вы можете получить значение отдельного текстового поля, используя var txtname= $('#txtid').val(); и проверьте, пусто ли имя txt или нет.

  • 0
    Я надеюсь ты ошибаешься. 'frmHomeContact' - это идентификатор внутренней формы.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню