我有一个网页,有两种形式。
像这样:<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
??
答案 0 :(得分:2)
您可以在Html.BeginForm
中使用ID
@using (Html.BeginForm("RegisterTenant", "Home", FormMethod.Post, new { id = "formID", enctype = "multipart/form-data" }))
和Jquery
$("#formID").on('submit',function (e){});
我想这是你要找的那个
答案 1 :(得分:1)
使用
$(document).ready(function () {
$(".TenantRegister form").on('submit', function (e) {});
});
在OP发布的代码中引用您的HTML
<div class="TenantRegister">
@using (Html.BeginForm("RegisterTenant", "Home", FormMethod.Post,
new { enctype = "multipart/form-data" }))
{