星空网 > 软件开发 > ASP.net

ASP.NEt MVC5

我们都知道,get方法,主要用来显示数据,检索之类,对数据一般不会修改。这次我做一个测试为Index方法写一个post方法。

1.get方式

public ActionResult Index(string searchString)
{

var movies = from m in db.Movies select m;

if (!string.IsNullOrEmpty(searchString))
{
movies = movies.Where(s => s.Title.Contains(searchString));
}
return View(movies);
}

实现的效果是:

ASP.NEt MVC5

 

下面我们来看看post方法:

1  [HttpPost]2     public string Index(FormCollection fc, string searchString)3     {4       return "<h3> From [HttpPost]Index: " + searchString + "</h3>";5     }

实现的效果是:

ASP.NEt MVC5

 

可以看到,现在post得到的页面,是纯文本的,没有链接。现在我想得到神话带链接的神话,我该咋办呢。。。

请看下面的方法。

打开Index视图,修改之前添加的form表单代码成:

1  @using(Html.BeginForm("Index","Movies",FormMethod.Get)){2   <p>3     Title:@Html.TextBox("SearchString")<br />4     <input type="submit" value="筛选" />5   </p>

 

现在来看一下效果:

ASP.NEt MVC5

Now when you submit a search, the URL contains a search query string.  Searching will also go to the HttpGet Index action method,  even if you have a HttpPost Index method.

即不允许表单以post方式提交。

 




原标题:ASP.NEt MVC5

关键词:ASP.NET

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

Petco:https://www.ikjzd.com/w/1573203548431622145
Pexda:https://www.ikjzd.com/w/1573203549124026370
PG Mall:https://www.ikjzd.com/w/1573203557202255874
柏域斯跨境物流:https://www.ikjzd.com/w/1573203557885583361
深圳柏域斯浩航跨境物流有限公司:https://www.ikjzd.com/w/1573203558368272385
Picasa3:https://www.ikjzd.com/w/1573203572318183425
亚龙湾有什么景点必看 亚龙湾有哪些景点:https://www.vstour.cn/a/408228.html
怀柔国际会议景点 怀柔国家会议中心门票:https://www.vstour.cn/a/408229.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流