ASP.NET MVC删除操作方法中的查询字符串
发布时间:2020-12-30 20:42:56 所属栏目: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将页面包装在一个表单中?
- 我应该在ASP.NET MVC中构建我的下一个Web应用程序吗?
- asp.net-mvc-2 – 带有数组/列表的ASP.NET MVC 2模型
- asp.net-mvc – ASP.NET MVC 3列表到IEnumerable
- 从ASP.Net中的sessionID获取会话对象
- asp.net – 在调用异步方法时不使用等待来防止死锁
- asp.net-mvc – 如何在视图上下文之外获取ModelMetadata?
- ASP.NET中上传并读取Excel文件数据示例
- asp.net页面SqlCacheDependency缓存实例
- asp.net-mvc – LabelFor和TextBoxFor不生成相同的id
推荐文章
站长推荐
- LoginView中的ASP.NET LoginStatus不会触发Loggi
- ASP.NET登录页面重定向问题
- 使用ASP.NET Identity 2.0和MVC 5进行自定义单点
- asp.net-mvc – ASP.NET MVC中的代码
- asp.net-mvc-3 – DropDownListFor Unobtrusive
- asp.net-mvc – MVC 5具有身份验证模式的外部身份
- asp.net – 更改事件和IE8的jQuery问题
- asp.net – 在渲染到位图之前缩放WPF内容
- ASP.NET Page_Init被解雇了两次!
- asp.net-mvc – 当Bundling EnableOptimizations
热点阅读
