ASP.NET MVC删除操作方法中的查询字符串
发布时间:2020-12-30 23:36:38 所属栏目:asp.Net 来源:互联网
导读:我有一个动作方法,如下所示: public ActionResult Index(string message){ if (message != null) { ViewBag.Message = message; } return View();} 发生什么事情是,对这个请求的URL将如下所示: www.mysite.com/controller/?message=H
我有一个动作方法,如下所示: public ActionResult Index(string message) { if (message != null) { ViewBag.Message = message; } return View(); } 发生什么事情是,对这个请求的URL将如下所示: www.mysite.com/controller/?message=Hello%20world 但我希望它看起来只是 www.mysite.com/controller/ 有没有办法删除actionmethod中的查询字符串? 解决方法不,除非你使用POST方法,否则信息必须通过某种方式.另一种可能是使用中间类.// this would work if you went to controller/SetMessage?message=hello%20world public ActionResult SetMessage(string message) { ViewBag.Message = message ?? ""; return RedirectToAction("Index"); } public ActionResult Index() { ViewBag.Message = TempData["message"] != null ? TempData["message"] : ""; return View(); } 要么.如果你只是使用一个POST //your view: @using(Html.BeginForm()) { @Html.TextBox("message") <input type="submit" value="submit" /> } [HttpGet] public ActionResult Index() { return View(); } [HttpPost] public ActionResult Index(FormCollection form) { ViewBag.Message = form["message"]; return View(); } (编辑:台州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET Core使用SkiaSharp实现验证码的示例代码
- ASP.NET MVC Web应用程序中视图逻辑和域逻辑之间的混淆
- .net – DNU发布 – 来自MSBuild的no-source
- asp.net核心 – 如何排除在ASP.NET Core中发布文件?
- asp.net-mvc – 尝试将asp.net web发布到Azure时,Visual St
- asp.net中mvc使用ajax提交参数的匹配问题解决探讨
- ASP.NET:从C#代码隐藏显示警报
- asp.net – 会话固定 – 表单身份验证
- ASP.NET(C#)应用程序配置文件app.config/web.config的增、删
- asp.net – 多个域的集成Windows身份验证
推荐文章
站长推荐
- asp.net-mvc – Nhibernate / MVC:在View中处理
- asp.net 文件上传实例汇总
- asp.net – WebFormsMVP的缺点?
- asp.net-core – 如何使用ASP.NET注册OData 5
- asp.net – 是否有可能过滤SignalR中的接收器?
- asp.net代码中修改web.config节点的具体方法
- 从asp.net mvc生成PDF文件
- asp.net – 什么时候Response.IsClientConnected
- asp.net – MVC 4导出到CSV – 另存为对话框在Ch
- asp.net-mvc – 如何在RegularExpression中忽略大
热点阅读