将路由值传递给Html.BeginForm [英] Passing route values to Html.BeginForm
问题描述
我希望表单将隐藏输入中的值传递给服务器,并且我还希望它将URL构造为本地主机:9392/Ranking/Index/2?rankingType = SOMEVALUE& ageGroup = SOMEVALUE& week = SOMEVALUE"
I want the form to pass the values from the hidden inputs to the server and I also expected it to build the URL as "localhost:9392/Ranking/Index/2?rankingType=SOMEVALUE&ageGroup=SOMEVALUE&week=SOMEVALUE"
但是它显示为"localhost:9392/Ranking/Index/2?rankingType = rankingTypeID& ageGroup = ageGroupID& week = week"
but it shows like "localhost:9392/Ranking/Index/2?rankingType=rankingTypeID&ageGroup=ageGroupID&week=week"
@using (Html.BeginForm("Index", "Ranking", new { id = Model.CurrentRanking, rankingType = "rankingTypeID", ageGroup = "ageGroupID", week = "week"}, FormMethod.Post, new { id = "ageGroupForm" }))
{
<input id="ageGroupID" name="ageGroup" hidden />
<input id="rankingTypeID" name="rankingType" hidden />
<input id="week" name="week" hidden />
}
那是为什么?如何传递值并使它们显示为查询字符串?
Why is that ? How do I pass the values and also have them show up as query string ?
推荐答案
尝试以下代码:
@using (Html.BeginForm("Index", "Ranking"))
{
<input id="ageGroupID" name="ageGroup" hidden />
<input id="rankingTypeID" name="rankingType" hidden />
<input id="week" name="week" hidden />
}
在您的操作方法中,将其装饰为:
and in your action method, decorate it like:
public ActionResult Index(string ageGroupID, string rankingTypeID, string week){}
这篇关于将路由值传递给Html.BeginForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!