我想确认这个限制是故意的还是我做错了什么:
我有两个RenderPartials视图:
@model Heelp.ViewModels.CompanyIndexViewModel
@{ Html.RenderPartial(MVC.Company.Views.IndexSearch, Model.SearchViewModel); }
@{ Html.RenderPartial(MVC.Company.Views.IndexMap, Model.MapViewModel); }
在第一个部分视图中,我有一个Ajax.BeginForm:
@model Heelp.ViewModels.CompanyIndexSearchViewModel
@using (Ajax.BeginForm(MVC.Company.CategoryGetAllBySearch(), new AjaxOptions { UpdateTargetId = "searchCompanyResults", InsertionMode = InsertionMode.Replace }, new { @id = "searchBoxWrap" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(m => m.IsCenterFromUser)
@Html.HiddenFor(m => m.CenterLat)
@Html.HiddenFor(m => m.CenterLng)
@Html.HiddenFor(m => m.Zoom)
@Html.HiddenFor(m => m.SearchRadius)
@Html.TextBoxFor(m => m.Search, new { @placeholder = @HeelpResources.CompanyIndexViewSearchPlaceholder })
<input type="button" value="«" id="clearKeywords"/>
@Html.TextBoxFor(m => m.Location, new { @placeholder = @HeelpResources.CompanyIndexViewLocationPlaceholder })
<input type="button" value="«" id="clearLocation"/>
<input type="button" value="X" id="hereButton"/>
<input type="submit" value="@HeelpResources.CompanyIndexViewSearchButtonLabel"/>
}
<div id="searchCompanyResults" class="clearfix" style="z-index: 10; position: absolute; width: 400px;"></div>
Ajax.BeginForm使用Ajax.ActionLink的列表在searchCompanyResults div中生成一个PartialView:
@model Heelp.ViewModels.CategoryGetAllBySearchListViewModel
<p class="float-left margin-top align-left"><span>Encontrámos <em><a href="#">@Model.TotalSearchCount</a></em> resultados nas categorias:</span></p>
<div class="clear-both">
<div id="searchResultsList" class="float-left">
<ul>
@foreach (var item in Model.CategoryGetAllBySearch)
{
<li>
@Ajax.ActionLink(
String.Format("{0} {1} ver »", item.SearchCount, item.Name),
MVC.Company.GetAllByCategory(item.Id, Model.Search, Model.Location, Model.IsCenterFromUser, Model.CenterLat, Model.CenterLng, Model.SearchRadius),
new AjaxOptions { OnBegin = "CompanyGetAllByCategoryOnBegin(" + item.Id + ")", OnSuccess = "CompanyGetAllByCategoryOnSuccess" })
</li>
}
</ul>
</div>
</div>
这里的问题是,如果我没有在PartialView中包含指向"< script PartialView >“的链接,Action.Link将返回Json文本。
编辑:我检测到的1是,当我单击Action.Link时,第一次提交是2次,第二次是4次,为什么?我一定要这么做吗?
发布于 2013-03-05 21:05:25
如果您想使用Ajax.BeginForm
、Ajax.ActionLink
和来自Ajax
的其他文件,您应该在布局中包含jquery.unobtrusion-ajax.js文件。它包含通过取消操作拦截、点击链接和提交表单的代码,并使其通过AJAX。
您不需要将该文件包含在部分视图中两次。
https://stackoverflow.com/questions/15233200
复制相似问题