ASP.NET MVC - html.beginForm在javascript中获取form信息

简介

Namespace:   System.Web.Mvc.Html System.Web.Mvc.Html 命名空间包含有助于在 MVC 应用程序中呈现 HTML 控件的类。 该命名空间包含支持窗体、输入控件、链接、分部视图、验证等的类
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

html.BeginForm: <form> 开始标记写入响应。 在用户提交窗体时,将由某个操作方法处理该请求。

BeginForm(HtmlHelper)

@using (Html.BeginForm())
{
    @Html.TextBox("Name");
    @Html.Password("Password");
    <input type="submit" value="Sign In">
}
// Produces the following form element
// <form action="/Original Controller/Original Action" action="post">

BeginForm(HtmlHelper, Object)

@<span style="color: blue;">using</span> (Html.BeginForm(<span style="color: blue;">new</span> { UserId = <span style="color: rgb(163, 21, 21);">"5"</span> }))
{
    @Html.TextBox(<span style="color: rgb(163, 21, 21);">"Name"</span>);
    @Html.Password(<span style="color: rgb(163, 21, 21);">"Password"</span>);
    <input type=<span style="color: rgb(163, 21, 21);">"submit"</span> value=<span style="color: rgb(163, 21, 21);">"Sign In"</span>>
}
<span style="color: green;">// Produces the following form element</span>
<span style="color: green;">// <form action="/Original Controller/Original Action?UserId=5" action="post"></span>

BeginForm(HtmlHelper, RouteValueDictionary)

@{
    var routeValues = new RouteValueDictionary();
    routeValues.Add("UserId", "5");
}
@using (Html.BeginForm(routeValues))
{
    @Html.TextBox("Name");
    @Html.Password("Password");
    <input type="submit" value="Sign In">
}
// Produces the following form element
// <form action="/Original Controller/Original Action?UserId=5" action="post">

BeginForm(HtmlHelper, String, String)

@{
    <span style="color: blue;">var</span> routeValues = <span style="color: blue;">new</span> RouteValueDictionary();
    routeValues.Add(<span style="color: rgb(163, 21, 21);">"UserId"</span>, <span style="color: rgb(163, 21, 21);">"5"</span>);
}
@<span style="color: blue;">using</span> (Html.BeginForm(routeValues))
{
    @Html.TextBox(<span style="color: rgb(163, 21, 21);">"Name"</span>);
    @Html.Password(<span style="color: rgb(163, 21, 21);">"Password"</span>);
    <input type=<span style="color: rgb(163, 21, 21);">"submit"</span> value=<span style="color: rgb(163, 21, 21);">"Sign In"</span>>
}
<span style="color: green;">// Produces the following form element</span>
<span style="color: green;">// <form action="/Original Controller/Original Action?UserId=5" action="post"></span>

BeginForm(HtmlHelper, String, String)

</pre><pre class="html" name="code">@using (Html.BeginForm("Login", "Account"))
{
    @Html.TextBox("Name");
    @Html.Password("Password");
    <input type="submit" value="Sign In">
}
// Produces the following form element
// <form action="/Account/Login" action="post">


BeginForm(HtmlHelper, String, String, FormMethod)

@using (Html.BeginForm("Login", "Account", FormMethod.Post))
{
    @Html.TextBox("Name");
    @Html.Password("Password");
    <input type="submit" value="Sign In">
}
// Produces the following form element
// <form action="/Account/Login" action="post">


BeginForm(HtmlHelper, String, String, FormMethod, IDictionary<String, Object>)

@{
    var attributes = new Dictionary<string, object>();
    attributes.Add("Id", "Form1");
}
@using (Html.BeginForm("Login", "Account", FormMethod.Post, attributes))
{
    @Html.TextBox("Name");
    @Html.Password("Password");
    <input type="submit" value="Sign In">
}
// Produces the following form element
// <form Id="Form1" action="/Account/Login" action="post">


BeginForm(HtmlHelper, String, String, FormMethod, Object)

@using (Html.BeginForm("Login", "Account", FormMethod.Post, new { Id = "Form1" }))
{
    @Html.TextBox("Name");
    @Html.Password("Password");
    <input type="submit" value="Sign In">
}
// Produces the following form element
// <form Id="Form1" action="/Account/Login" action="post">

BeginForm(HtmlHelper, String, String, Object)

@using (Html.BeginForm("Login", "Account", new { UserId = "5" }))
{
    @Html.TextBox("Name");
    @Html.Password("Password");
    <input type="submit" value="Sign In">
}
// Produces the following form element
// <form action="/Account/Login?UserId=5" action="post">

BeginForm(HtmlHelper, String, String, Object, FormMethod)

@using (Html.BeginForm("Login", "Account", new { UserId = "5" }, FormMethod.Post))
{
    @Html.TextBox("Name");
    @Html.Password("Password");
    <input type="submit" value="Sign In">
}
// Produces the following form element
// <form action="/Account/Login?UserId=5" action="post">

BeginForm(HtmlHelper, String, String, Object, FormMethod, Object)

@using (Html.BeginForm("Login", "Account", new { UserId = "5" }, FormMethod.Post, new { Id = "Form1" }))
{
    @Html.TextBox("Name");
    @Html.Password("Password");
    <input type="submit" value="Sign In">
}
// Produces the following form element
// <form Id="Form1" action="/Account/Login?UserId=5" action="post">

BeginForm(HtmlHelper, String, String, RouteValueDictionary)

@{
    var routeValues = new RouteValueDictionary();
    routeValues.Add("UserId", "5");
}
@using (Html.BeginForm("Login", "Account", routeValues))
{
    @Html.TextBox("Name");
    @Html.Password("Password");
    <input type="submit" value="Sign In">
}
// Produces the following form element
// <form action="/Account/Login?UserId=5" action="post">


BeginForm(HtmlHelper, String, String, RouteValueDictionary, FormMethod)
BeginForm(HtmlHelper, String, String, RouteValueDictionary, FormMethod, IDictionary<String, Object>)

访问form元素

  • 如果在当前page中只有一个form:
// find forms in the page
   $("form")
  • html.BeginForm 构造函数传入 form Id。如:
@using (Html.BeginForm("Login", "Account", FormMethod.Post, new { Id = "Form1" })){ //element}
@using (Html.BeginForm("Login", "Account", new { UserId = "5" }, FormMethod.Post, new { Id = "Form1" }))

           访问form:

// find the form by id
   $("#myForm1");





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值