ASP.NET MVC删除操作方法中的查询字符串
发布时间:2020-12-31 01:24:52 所属栏目: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 – 帖子上的Mvc模型ID 0
- asp.net – UserControl Viewstate在回发后丢失所有值
- asp.net-mvc – 存储库与DAL中的服务模式:EF和Dapper
- asp.net-mvc – 为什么MVC4捆绑捆绑Knockout.js?
- asp.net-mvc – 带vNext的MVC 6:我们还需要Global.asax吗?
- asp.net-mvc-3 – Telerik MVC网格,在运行时从集合或字典中
- asp.net-mvc – ASP.NET MVC中的Windows Live ID
- ASP.NET汉字转拼音 - 输入汉字获取其拼音的具体实现
- ASP.NET Web应用程序的安装
- asp.net – 在MVC3或IIS 7.5中禁用x-frame-options
推荐文章
站长推荐
- 是否可以使用ASP.NET ScriptManager来使用Window
- asp.net-mvc – 带vNext的MVC 6:我们还需要Glob
- 如何将数组从Asp.net服务器端传递到客户端的Java
- asp.net-mvc – 不要在ASP .NET MVC 4 BundleCon
- ASP.NET:预编译文件的文件名生成规则
- asp.net-mvc – 具有ASP.NET MVC的多语言网站
- asp.net-mvc-2 – 使用’class(或其他保留关键字
- asp.net – Orchard CMS是否支持移动呈现?
- asp.net – 从启用AJAX的WCF服务返回错误详细信息
- 如何为Asp.Net中的所有子文件夹注册HttpHandler?
热点阅读
