Как определить идентификатор формы в MVC4

0

У меня есть веб-страница, которая имеет две формы.

как это:

<div class="ApartmentOwnerRegister">
@using (Html.BeginForm("RegisterApartmentOwner", "Home", FormMethod.Post, 
                            new { enctype = "multipart/form-data" }))
                            {
    <p>
        <label>First Name</label>
        <input type="text" placeholder="Enter your first Name" />
        <span class="errorMessage"></span>
    </p>
    <p>
        <label>Last Name</label>
        <input type="text" placeholder="Enter your last Name" />
        <span class="errorMessage"></span>
    </p>
    <p>
        <label>Mobile Number</label>
        <input type="text" placeholder="Enter your mobile number" />
        <span class="errorMessage"></span>
    </p>
    <p>
        <input type="submit" value="Register"  class="submit"/>
    </p>
    }
</div>
<div class="TenantRegister">
@using (Html.BeginForm("RegisterTenant", "Home", FormMethod.Post, 
                            new { enctype = "multipart/form-data" }))
                            {
    <p>
        <label>First Name</label>
        <input type="text" placeholder="Enter your first Name" />
        <span class="errorMessage"></span>
    </p>
    <p>
        <label>Last Name</label>
        <input type="text" placeholder="Enter your last Name" />
        <span class="errorMessage"></span>
    </p>
    <p>
        <label>Mobile Number</label>
        <input type="text" placeholder="Enter your mobile number" />
        <span class="errorMessage"></span>
    </p>
    <p>
        <label>Passport Number</label>
        <input type="text" placeholder="Enter your passport number" />
        <span class="errorMessage"></span>
    </p>

    <p>
        <label for="file">Upload You Passport:</label> 
        <input type="file" name="file" id="passport" style="width: 100%;" />  
        <span class="errorMessage"></span>
    </p>
    <p>
        <label for="file">Upload You Image:</label> 
        <input type="file" name="file" id="image" style="width: 100%;" />  
        <span class="errorMessage"></span>
    </p>
    <p>
        <input type="submit" value="Register"  class="submit"/>
    </p>
}
    </div>

что пользователь отправляет форму, я хочу вызвать функцию jquery.

в прошлом, без mvc, я делал это:

$("#formID").on('submit',function (e){});

но в том коде, что я должен делать вместо formID??

Теги:
asp.net-mvc
asp.net-mvc-4

2 ответа

1
Лучший ответ

использование

$(document).ready(function () {
    $(".TenantRegister form").on('submit', function (e) {});
});

Ссылаясь на ваш HTML ниже в OP, размещенном в коде

<div class="TenantRegister">
@using (Html.BeginForm("RegisterTenant", "Home", FormMethod.Post, 
                            new { enctype = "multipart/form-data" }))
                            {
  • 0
    без документа .читать?
  • 0
    @MarcoDinatsoli use $(document).ready(function () { Проверить обновленный ответ.
Показать ещё 5 комментариев
2

Вы можете использовать id в своем Html.BeginForm как

@using (Html.BeginForm("RegisterTenant", "Home", FormMethod.Post, new { id = "formID", enctype = "multipart/form-data" }))

и JQuery

$("#formID").on('submit',function (e){});

Я думаю, это тот, который вы ищете

Ещё вопросы

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