ASP.NET MVC删除操作方法中的查询字符串
发布时间:2020-12-30 20:44:18 所属栏目: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 – 如何添加.aspx页面到现有的MVC 4项目?
- ASP.NET MVC 4 JSON绑定到视图模型 – 嵌套对象错误
- asp.net – 渗透测试人员说.ASPXAUTH cookie是不安全的并且
- ASP.NET Core 2.0中Razor页面禁用防伪令牌验证
- 我如何让Fiddler捕获我的MVC应用程序向我的ASP.NET Web API
- asp.net-mvc-2 – 使用’class(或其他保留关键字)作为匿名类
- asp.net-mvc – URL中的ASP.NET MVC冒号
- asp.net-mvc – 允许asp.net mvc 2控制器名称的URL中的连字
- asp.net-core – .net核心自定义身份验证中的User.Identity
- asp.net-mvc – 使用AWS .NET SDK进行SNS订阅确认示例
推荐文章
站长推荐
- asp.net-core – .net核心自定义身份验证中的Use
- asp.net字符串分割函数使用方法分享
- asp.net – 从我的GridView行返回一个对象
- ASP.Net:为什么我的按钮的点击/命令事件没有在转
- asp.net-mvc-3 – MVC 3 $.ajax – 响应似乎是从
- asp.net-web-api – 使用swashbuckle api文档的h
- asp.net-mvc – 如何组合两个dataTextFields的Se
- asp.net-mvc – 在MVC4中为ViewModel设置默认值的
- ASP.NET网址MAX_PATH限制
- asp.net – 如何使用Inno Setup脚本创建IIS应用程
热点阅读