asp.net-mvc – 使用Html.BeginForm与querystring
|
我的网址如下所示: customer/login?ReturnUrl=home 在登录视图中,我使用了这种可以正常工作的代码模式。 @using(Html.BeginForm())
{
...
}
这神奇地生成以下html <form action="customer/login?ReturnUrl=home" method="post"> 但现在,我需要在表单中添加一个属性(例如,data-id =“something”)。我怎样才能做到这一点?如果我没有任何查询字符串,我知道我可以这样做: @using(Html.BeginForm(action,controller,FormMethod.Post,new { data_id="something" }))
但是不知道如何添加应该在html中的querystring: <form action="customer/login?ReturnUrl=home" method="post" data-id="something"> 我想到了使用< form>直接但不知道如何指定querystring哪个是可变的。我不知道如何用Html.BeginForm来实现它。任何提示将不胜感激。 解析度: 现在,我使用了< form>具有以下提示How to get current url value in View.结果视图看起来像 <form action="@Request.Url.PathAndQuery" data-id="something" method="POST"> 但是对于这一点,可以使用BeginForm的重载方法。 解决方法我猜这不直接回答这个问题,但是为什么不使用一个简单的旧格式标签?<form action='customer/login?ReturnUrl=@Request.QueryString["ReturnUrl"]' method="post" data-id="something"> 或者,您可以创建一个自定义的HtmlHelperExtension,它使用路径和查询字符串呈现表单。在这个HtmlHelperExtension中,您可以遍历查询字符串值并填充routeValueDictionary,然后传递给Html.BeginForm构造函数。 如果你不想要这样可扩展的东西,你可以使用Html.BeginForm的重载构造函数@ Html.BeginForm(“login”,“customer”,new {ReturnUrl = @ Request.QueryString [“ReturnUrl”]},FormMethod.Post,new {data-id =“something”}); (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 从项目中的一个ASP.NET页面中删除主题
- 体验使用gcServer =“true”为.NET设置垃圾回收器
- asp.net-mvc – mvc3 maxLength输入
- asp.net-mvc-4 – Kendo UI组合框复位值
- asp.net-mvc-3 – 列模板kendo ui grid mvc动作链接
- asp.net-mvc – ASP.NET MVC在新窗口中打开pdf文件
- asp.net-web-api – HttpClient不报告从Web API返回的异常
- 在ASP.NET中使用回发的jQuery模态对话框
- ASP.NET Web API将http响应转换为json数组
- asp.net – 当页面在iFrame中时,会话变量不会保存
- 在ASP.net中使用NVP API时,PayPal SetExpressChe
- asp.net核心 – 为什么验证类型 – .NET Core中的
- asp.net – 如何在selectindexchanged下拉列表后
- asp.net-mvc – 使用MVC Web应用程序时Nhibernat
- 如何自定义ASP.NET Web API AuthorizeAttribute的
- asp.net-mvc-4 – 使用@ Url.Content(“”)有什么
- asp.net-mvc – 在MVC 3模型ID属性中将ScaffoldC
- asp.net – 调试时编辑源代码
- asp.net-web-api – Asp.net WebApi将UTC时间字符
- asp.net – 转发器控件中的单选按钮列表
