ASP.NET MVC删除操作方法中的查询字符串
发布时间:2020-12-31 00:09:59 所属栏目: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(); } (编辑:4S站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – IE10中的LinkButtons不执行回发
- asp.net-mvc-3 – 如何避免使用MVC3 FileContentResult重复
- asp.net – 从我的GridView行返回一个对象
- asp.net – 如何在C#2.0中的Web.config中加密用户名和密码
- asp.net – 如何使用Inno Setup脚本创建IIS应用程序和应用程
- 在ASP.net中使用NVP API时,PayPal SetExpressCheckout存在问
- ASP.NET core Web中使用appsettings.json配置文件的方法
- ASP.NET通过自定义函数实现对字符串的大小写切换功能
- asp.net – Windows应用程序与Web应用程序开发
- asp.net-mvc – 为什么这个路由参数被添加到查询字符串中?
推荐文章
站长推荐
- asp.net-mvc – ASP.NET MVC:在其中生成带有自定
- asp.net – jquery getJson没有将任何值传递给控
- 详解Asp.net Core 使用Redis存储Session
- asp.net – [DataType(DataType.EmailAddress)]和
- asp.net-core – .NET Core SDK安装程序无法在Wi
- asp.net-mvc-3 – MVC3视图继承不可能?
- asp.net-mvc – ASP.NET MVC检查Controller或Act
- asp.net – ASP.NET中的“关键字不支持:”错误
- asp.net-mvc – 值不能为空或为空.参数名称:con
- asp.net-mvc-3 – 依赖注入与多个类实现的接口
热点阅读