簡體   English   中英

MVC4 Ajax不呈現ActionLink

[英]MVC4 Ajax not rendering ActionLink

我來自webforms背景,此時我對MVC4感到非常沮喪。 我一直在看例子,看視頻,谷歌搜索等。 似乎沒有什么工作,我即將放棄,但是,這個網站非常有幫助,所以我將看看我是否可以得到一些幫助。

我想做的是:

  1. 用jQuery選項卡創建一個頁面(easytabs)(這是btw完成的)
  2. 在標簽點擊事件中,我希望它通過ajax重新加載標簽

在webforms中,我會在早上8點完成。 我現在堅持這個和下午5點。 沮喪超越信仰。

我關注了MVC4網站上的網絡視頻教程,這個可愛的例子是在Razor中,我不想使用它,但是,我還是會依照它知道:

http://www.asp.net/mvc/overview/javascript
- >'Javascript和Ajax'
- > http://pluralsight.com/training/players/PSODPlayer?author=scott-allen&name=mvc3-building-ajax&mode=live&clip=0&course=aspdotnet-mvc3-intro

在我的easytabs中,在HTML中,我將我的html定義為:

<li class="tab"><a href="#tabs-users" class="light heavy">Manage Sections</a></li>

因此,在視頻之后,我嘗試通過ajax幫助程序創建並錨定帶有ajax屬性的標記來替換此HTML:

 <% Ajax.ActionLink("Manage Sections", "tabsUsers", new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "tabs-users", InsertionMode = InsertionMode.Replace }); %>

這使得沒什么。 它不會在頁面上呈現它。 所以,我去打獵,發現我需要以下內容:

<%: Scripts.Render("~/bundles/jqueryval") %>

這個包包括' jquery.unobtrusive-ajax.min.js '以及web.config我有以下設置:

<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

依然沒有。

原始HTML

<div id="tab-container" class="tab-container">
    <ul class="etabs">
        <li class="tab upper first"><a href="#tabs-users" class="light heavy">Manage Users</a></li>
        <li class="tab upper"><a href="#tabs-groups" class="light heavy">Manage Sections</a></li>
    </ul>
    <div id="tabs-users" class="normal light clearfix">
        Users
    </div>
    <div id="tabs-groups" class="normal light clearfix">
        Groups
    </div>
</div>

我有一種感覺,Ajax.ActionLink不喜歡在那里渲染錨標記,但我不知道為什么。

調節器

    [HttpGet]
    public PartialViewResult tabsUsers()
    {
        IEnumerable<SelectListItem> items = UserManager.GetUsers()
            .Select(c => new SelectListItem
            {
                Value = c.UserID.ToString(),
                Text = c.FirstName + c.LastName
            });

        return PartialView("UsersPartial", items);
    }

UsersPartial View

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<LMS.Data.User>>" %>

<table>
    <tr>
        <th>
            <%: Html.DisplayNameFor(model => model.UserName) %>
        </th>
        <th>
            <%: Html.DisplayNameFor(model => model.FirstName) %>
        </th>
        <th>
            <%: Html.DisplayNameFor(model => model.LastName) %>
        </th>
        <th>
            <%: Html.DisplayNameFor(model => model.Password) %>
        </th>
        <th>
            <%: Html.DisplayNameFor(model => model.Email) %>
        </th>
        <th></th>
    </tr>

<% foreach (var item in Model) { %>
    <tr>
        <td>
            <%: Html.DisplayFor(modelItem => item.UserName) %>
        </td>
        <td>
            <%: Html.DisplayFor(modelItem => item.FirstName) %>
        </td>
        <td>
            <%: Html.DisplayFor(modelItem => item.LastName) %>
        </td>
        <td>
            <%: Html.DisplayFor(modelItem => item.Password) %>
        </td>
        <td>
            <%: Html.DisplayFor(modelItem => item.Email) %>
        </td>
        <td>
            <%: Html.ActionLink("Edit", "Edit", new { id=item.UserID }) %> |
            <%: Html.ActionLink("Details", "Details", new { id=item.UserID }) %> |
            <%: Html.ActionLink("Delete", "Delete", new { id=item.UserID }) %>
        </td>
    </tr>
<% } %>

</table>

腳本部分在運行時呈現

        <script src="/Scripts/jquery-1.6.2.js" type="text/javascript"></script>

        <script src="/Scripts/jquery.unobtrusive-ajax.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js" type="text/javascript"></script>

        <script src="/Scripts/jquery-ui-1.8.11.js" type="text/javascript"></script>

        <script src="/Scripts/jquery.easytabs.min.js" type="text/javascript"></script>
<script src="/Scripts/script.js" type="text/javascript"></script>

有任何想法嗎?? 我真的想在這里給MVC一個有價值的鏡頭,但對我來說並不是很好。

這使得沒什么。 它不會在頁面上呈現它。

那是因為正確的語法如下:

<%= Ajax.ActionLink("Manage Sections", "tabsUsers", new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "tabs-users", InsertionMode = InsertionMode.Replace }) %>

由於很長一段時間WebForms用戶在早上8點完成工作,你應該知道<%=用於將結果輸出到響應,而<%和a ; 最后只需在服務器上執行命令而不輸出任何內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM