0
我想確認,如果這種限制是通過設計還是我做錯了什麼:Ajax.ActionLink
我有兩個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產生的searchCompanyResults DIV一個PartialView與Ajax.ActionLink的列表:
@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鏈接到 「<腳本SRC =」 〜/腳本/ jquery.unobtrusive-ajax.min.js 「>」 的行動。鏈接返回Json文本。
編輯:我發現的一個問題是,當我點擊Action.Link時,第一次提交2次,第二次提交4次,爲什麼? 我必須這樣做嗎?
嗨,謝謝。如果它在View中調用RenderPartial,則它不起作用,只能在列出Ajax.Actions的部分視圖中使用 – Patrick 2013-03-06 12:25:19