我有以下观点
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using( Html.BeginForm("Create", "Concepts", new { name="sfsfsfsfsf", gio="sfsf9s9f0sffsdffs", ford="mtp"}, FormMethod.Get, null ) )
{
<input type="submit" name="name" value="New" />
}
当我点击新按钮时,如何在网址上显示值gio
,ford
和name
?
这是我的路线定义
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
答案 0 :(得分:1)
您使用BeginForm()
正在添加3个路由值,而不是查询字符串值。如果您要生成.../Concepts/Create/sfsfsfsfsf/sfsf9s9f0sffsdffs/mtp
的网址(ConceptsController
)
public ActionResult Create(string name, string gio, string ford)
然后你需要添加以下路由定义(它需要在默认路由之前
routes.MapRoute(
name: "Create",
url: "Concepts/Create/{name}/{gio}/{ford}",
defaults: new { controller = "Concepts", action = "Create" }
);
另请注意,由于与路径参数冲突,您需要从提交按钮中删除name="name"
或者,如果您需要.../Concepts/Create?name=sfsfsfsfsf@&gio=sfsf9s9f0sffsdffs&ford=mtp
,则删除路径参数并为值添加输入
@using( Html.BeginForm("Create", "Concepts", FormMethod.Get) )
{
<input name="name" value="sfsfsfsfsf" />
<input name="gio" value="sfsf9s9f0sffsdffs" />
<input name="ford" value="mtp" />
<input type="submit" value="New" />
}