C# 将html文本框值作为参数传递给asp.net MVC中的控制器方法
我想将C# 将html文本框值作为参数传递给asp.net MVC中的控制器方法,c#,asp.net,asp.net-mvc,asp.net-mvc-3,asp.net-mvc-4,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 3,Asp.net Mvc 4,我想将Html.Textbox值从锚标记传递给控制器,以便搜索传递给控制器的值。请告诉我如何才能做到这一点 <a href="@Url.Action("Index", "Home", new { })">@p</a> public ActionResult Index(string String) { } @Html.TextBox("String") 公共操作结果索引(字符串) { } @文本框(“字符串”) 使用jque
Html.Textbox
值从锚标记传递给控制器,以便搜索传递给控制器的值。请告诉我如何才能做到这一点
<a href="@Url.Action("Index", "Home", new { })">@p</a>
public ActionResult Index(string String)
{
}
@Html.TextBox("String")
公共操作结果索引(字符串)
{
}
@文本框(“字符串”)
使用jquery
@Html.TextBox("String", null, new { @class="txtString" })
<a href="@Url.Action("Index", "Home", new { })" class="linkAction">@p</a>
使用jquery
@Html.TextBox("String", null, new { @class="txtString" })
<a href="@Url.Action("Index", "Home", new { })" class="linkAction">@p</a>
您不必使用jQuery。如果您正在执行一个
HttpPost
,则只需输入文本框的“名称”
在您的页面上:
@using (Html.BeginForm("Index", FormMethod.Post)) {
@Html.TextBox(string.Empty, new { name = "textbox" })
<input type="submit">Submit</input>
}
您不必使用jQuery。如果您正在执行一个
HttpPost
,则只需输入文本框的“名称”
在您的页面上:
@using (Html.BeginForm("Index", FormMethod.Post)) {
@Html.TextBox(string.Empty, new { name = "textbox" })
<input type="submit">Submit</input>
}
@使用(Html.BeginForm(“Index”,“Home”,null,FormMethod.Post,new{@id=“my form”}))
{
@文本框(“字符串”)
}
您可以使用FormMethod.Post
或FormMethod.Get
。后者将使用(Html.BeginForm(“Index”,“Home”,null,FormMethod.Post,new{@id=“my form”}))向url追加?String=。@
{
@文本框(“字符串”)
}
您可以使用
FormMethod.Post
或FormMethod.Get
。后者将向url追加?String=。它在文本框中显示{class=txtString}。语法有错误吗?抱歉,请将类放入对象值而不是html值中。为对象值添加了一个空值,因此现在应该正确呈现它在文本框中显示{class=txtString}。语法有错误吗?抱歉,请将类放入对象值而不是html值中。为对象值添加了一个空值,这样它现在应该可以正确呈现。我可以在传递页码时使用锚标记传递名称吗,如下所示:为此,必须使用jQuery和Matt的答案。使用这样的表单实际上是一种更为公认的做法,因为您希望从服务器上的客户端检索动态信息。这一切都取决于你如何使用它,以及你想遵循哪种约定。string.empty应该是string.empty,带有大写字母:ECan我可以在传递页码时借助锚定标记传递姓名,如下所示:为此,你必须使用jQuery和Matt的答案。使用这样的表单实际上是一种更为公认的做法,因为您希望从服务器上的客户端检索动态信息。这完全取决于您如何使用它,以及您希望遵循的约定。string.empty应该是string.empty,并带有大写字母:E
@using (Html.BeginForm("Index", "Home", null, FormMethod.Post, new {@id = "my-form"}))
{
@Html.TextBox("String")
}
<a href="javascript:document.getElementById('my-form').submit();>@p</a>