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

4

2 回答 2

2

你可以用你Html.BeginForm喜欢的 id

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

和jQuery

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

我想这就是你要找的那个

于 2013-10-26T14:52:36.053 回答
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" }))
                            {
于 2013-10-26T14:42:23.600 回答