ASP.NET MVC删除操作方法中的查询字符串
发布时间:2020-12-30 21:21:08 所属栏目: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 – web部署工具2.1和web部署3.5有什么区别?哪一个
- asp.net-core – 如何使用ASP.NET注册OData 5
- 使用SharpZipLib压缩打包多个内存中的文件
- asp.net – 我可以在超链接上显式指定NavigateUrl吗?
- 谈谈.NET Core中基于Generic Host来实现后台任务
- asp.net字符串分割函数使用方法分享
- asp.net-mvc-3 – 具有最佳实践的示例N层ASP.NET MVC3应用程
- 使用MVC在ASP.NET中实现API的最佳方法是什么?
- asp.net – 动态创建和共享Google云端硬盘文件夹
- asp.net – 在Azure网站上启用gzip压缩
推荐文章
站长推荐
- asp.net-mvc – Visual Studio 2010 Full和ASP.N
- asp.net – 在为app_offline.htm提供特定URL时,将
- asp.net-mvc-3 – 将数组传递给RouteValues,并将
- 扩展ASP.NET数据缓存以在Web场之间共享
- asp.net-core – 找不到Swashbuckle.AspNetCore
- asp.net-core – 我为什么要选择带有.Net核心的A
- asp.net-core – ASP.Net核心maxUrlLength
- Jquery+ajax请求data显示在GridView上(asp.net)
- 文档在线预览的实现
- Asp.net Core 1.1 升级后操作mysql出错的解决办法
热点阅读