ASP.NET MVC删除操作方法中的查询字符串
发布时间:2020-12-30 20:28:16 所属栏目: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 – Silverlight初始化错误2110 Internet Explorer
- ASP.Net:为什么我的按钮的点击/命令事件没有在转发器中绑定
- asp.net-mvc – 使用Asp.net MVC 4中的OutputCacheAttribut
- asp.net-mvc-4 – 在哪里可以找到WebMatrix.WebData.WebSec
- asp.net-mvc – 使用Entity FrameWork保存更改/更新数据集中
- asp.net-mvc – 在Asp.Net MVC中使用千位分隔符的十进制值
- asp.net-mvc – 找到相同类型的两个实体之间的差异
- asp.net-mvc – 只发布控制器
- asp.net-mvc – ASP.NET MVC模型/ ViewModel验证
- 在ASP.NET MVC中动态地从数据库生成CSS文件
推荐文章
站长推荐
- asp.net-mvc – MVC错误 – 传入字典的模型项目的
- asp.net – 从我的GridView行返回一个对象
- 详解ASP.NET Core 中的框架级依赖注入
- asp.net-mvc – 缩小ASP.NET MVC中的Action Filt
- asp.net-mvc – ASP.NET MVC 3 Beta 1 Block访问
- ASP.NET汉字转拼音 - 输入汉字获取其拼音的具体实
- 增加ASP.NET站点的executionTimeout和maxRequest
- Asp.NEt邮箱验证修改密码通过邮箱找回密码功能
- asp.net – 如何使用Fiddler编辑HTTP请求
- asp.net-mvc-3 – 使用@ Html.Raw有风险吗?
热点阅读
