每次<a>
標記被按下,我需要提交表單。我需要跟蹤<a>
標籤被按下的次數。它以3開頭,每次提交時我們都增加6.我需要使用Action Method將此數字傳遞給GetArticleData Controller。需要Javascript或jQuery代碼將數據傳遞給控制器
@{
Layout = "~/Views/Shared/_MasterLayout.cshtml";
AjaxOptions ajaxOpts = new AjaxOptions
{
UpdateTargetId = "tableBody",
Url = Url.Action("GetArticleData")
};
}
<div class="headlines-show-more">
@using(Ajax.BeginForm(ajaxOpts))
{
<a class="button-add-content" href="#">Show More News</a>
}
</div>
<div id="tableBody">
@Html.Action("GetArticleData");
</div>
控制器
public PartialViewResult GetArticleData()
{
HomePageModel model = new HomePageModel();
model.GetDetails();
return PartialView(model);
}
管窺
@model Models.HomePageModel
@foreach(var item in Model.HeadlinesNews.Skip(0).Reverse().Take(9))
{
<a href="@Url.Action("Index", "Article", new { id = item.PKNewsId, title = item.NewsTitle.Replace(' ', '-') })">
<span>
<span>@item.Category</span>
<span></span>
<img src="@Url.Content("~/Uploads/Images/" + item.Image)">
<span>
<span></span>
<p>@item.NewsTitle</p>
</span>
</span>
</a>
}
那麼是什麼問題呢?你得到什麼錯誤?您應該只需要將updatetargetid添加到開始表單調用以引用您調用Html.Action(「GetArticleData」)的div, – ryanulit 2015-03-02 19:03:47
是updatetargetid存在,但我需要傳遞該次數 tag被按下,所以它可以從模型中獲取更多記錄。所以第一次加載它顯示3,你按標記它提取6多,你再次按下它獲取6更多等等 – user2224493 2015-03-02 19:09:11
你不能只更新隱藏的輸入? – charlietfl 2015-03-02 19:11:01