Ajax.begin预加载数据
我有这样的观点,Ajax的一切都很好。BeginForm:Ajax.begin预加载数据,ajax,asp.net-mvc,Ajax,Asp.net Mvc,我有这样的观点,Ajax的一切都很好。BeginForm: <h2>Index</h2> @using (Ajax.BeginForm("Search", new AjaxOptions { HttpMethod = "GET", InsertionMode = InsertionMode.Replace, UpdateTargetId = "users" })) { <input name="q" type="text" /&
<h2>Index</h2>
@using (Ajax.BeginForm("Search", new AjaxOptions {
HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "users"
})) {
<input name="q" type="text" />
<input type="submit" value="Search" />
}
<div class="table-responsive" id="users">
</div>
索引
@使用(Ajax.BeginForm(“搜索”),新的AjaxOptions{
HttpMethod=“GET”,
InsertionMode=InsertionMode.Replace,
UpdateTargetId=“用户”
})) {
}
但是,我有一个小问题
现在,当我打开此页面时,没有包含数据的表-它仅在提交表单时加载
所以,我的问题是:是否可以预加载数据(而不添加其他代码)
加载页面时,我希望所有数据都不经过筛选(输入用于在键入值和提交表单时进行筛选)。加载页面时,只需从
用户
div调用您的搜索
操作即可。您不能指定任何参数或使用默认参数。我想你有这样的东西:
public ActionResult Search(string q)
{
var users = _usersRepository.GetAll();
if(!string.IsNullOrEmpty(q))
users = users.Where(user => string.Equals(user.Name, q));
return PartialView("_Search", users);
}
并且认为:
<div class="table-responsive" id="users">
@Html.Action("Search")
</div>
@Html.Action(“搜索”)
哦,太好了。奇怪的是,我忘记了这个可能的行动,泰;)