ASP.NET MVC删除操作方法中的查询字符串
发布时间:2020-12-30 20:42:41 所属栏目: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-mvc – 不应加载引用程序集以执行
- Asp.NET控制文件上传的大小方法(超简单)
- ASP.NET Response.Cache.SetNoStore()与Response.Cache.Set
- 在ASP.Net MVC应用程序中放置初始化代码的位置?
- 端到ASP.NET MVC的推荐方法
- asp.net – 访问asp:从代码背后的内容
- ASP.Net下载大文件的实现方法
- asp.net – 通过邮件发送wcf服务消费表单数据
- asp.net-mvc – 为什么在ASP.NET MVC中使用lambdas而不是反
- asp.net-mvc – 有没有办法重命名RequestVerificationToken
推荐文章
站长推荐
- asp.net – 双回发问题
- asp.net – 如何从TableAdapter中检索存储过程返
- asp.net-mvc-3 – 应该使用HTTP引用来验证还是令
- 利用ASP.NET MVC和Bootstrap快速搭建个人博客之后
- asp.net – 在客户端启用/禁用RequiredValidator
- 认证 – WebApi ActionFilterAttribute,HttpActi
- asp.net – HttpWebRequest正在为404抛出异常
- ASP.NET Core中调整HTTP请求大小的几种方法详解
- asp.net – Tridion分析和个性化错误:用户不能为
- asp.net-mvc – 什么时候使用ViewData而不是View
热点阅读
