ASP.NET MVC删除操作方法中的查询字符串
发布时间:2020-12-30 20:45:50 所属栏目: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.config中数据库连接字符串connectionStrings节
- asp.net 大文件上传 之 改版了的SlickUpload.HttpUploadMod
- asp.net web大文件上传带进度条实例代码
- asp.net – .NET Web API 2 OWIN承载令牌认证
- asp.net-mvc – 为什么MVC4捆绑捆绑Knockout.js?
- asp.net-mvc – 为什么在我的ASP MVC4应用程序中重定向资源
- asp.net-mvc – 使用jQuery.post将多个参数发布到MVC Contr
- 敏感词汇过滤DFA算法
- asp.net-mvc – 用于选择的KendoUI网格Ajax绑定参数
- 使用Asp.net Web API时,使用DataContract和DataMember属性有
推荐文章
站长推荐
- asp.net – Visual Studio – 为什么.ASPX文件比
- asp.net – Windows应用程序与Web应用程序开发
- asp.net – 使用app_offline.htm使应用程序脱机,
- asp.net-mvc-3 – 在同一父视图上多次使用一个部
- asp.net结合Ajax验证用户名是否存在的代码
- asp.net – 让Visual Studios使用子域名?
- asp.net – [DataType(DataType.EmailAddress)]和
- IIS 7中为ASP.NET缺少MIME类型404.17
- asp.net-mvc – 使用复杂类型嵌套对象的bind属性
- asp.net(C#)把汉字转化成全拼音函数(全拼)
热点阅读