Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I dynamically add an Actionlink from the Controller in MVC 4
    primarykey
    data
    text
    <pre><code> [HttpGet] public JsonResult EfficientPaging(int? page = null, string searchParam = null) { int skip = page.HasValue ? page.Value - 1 : 0; _users = db.Users.Select(u =&gt; u).ToList(); var data = _users.Skip(skip * 10).Take(10).ToList(); var empty = _users.Any(); var count = Convert.ToInt32(Math.Ceiling(_users.Count() / 10.0)); if (!string.IsNullOrEmpty(searchParam)) { empty = !_users.Any(u =&gt; u.last_name.ToLower().Contains(searchParam.ToLower())); count = _users.Count(u =&gt; u.last_name.ToLower().Contains(searchParam.ToLower())); data = _users.Where(u =&gt; u.last_name.ToLower().Contains(searchParam.ToLower())) .Skip(skip * 10) .Take(10) .ToList(); } var grid = new WebGrid(data); var htmlString = grid.GetHtml(tableStyle: "webGrid", headerStyle: "header", alternatingRowStyle: "alt", htmlAttributes: new {id = "DataTable"}, columns: grid.Columns( grid.Column("first_name", "First"), grid.Column("last_name", "Last"), grid.Column("username", "Username"), grid.Column("password_expiration", "Expired"), grid.Column("locked", "Locked"), grid.Column(format: (item) =&gt; Html.Actionlink("Edit", "Edit", "User", new { userId = item.id }, null)))); return Json(new { Data = htmlString.ToHtmlString(), Count = count, Empty = empty }, JsonRequestBehavior.AllowGet); } </code></pre> <p>JQuery:</p> <pre><code>$(document).ready(function () { $('input').keyup(function () { var name = $(this).attr("name"); var searchParameter = $(this).val(); var element = $(this); $.ajax({ type: "GET", url: "User/EfficientPaging", data: { searchParam: searchParameter }, dataType: "json", success: function (d) { element.parent().parent().find(".file").empty(); if (d.Empty) { element.parent().parent().find(".file").append("&lt;span style='color: black' &gt;No files in this folder.&lt;/span&gt;"); element.parent().parent().find(".pagination").empty(); element.parent().parent().find(".pagination").hide(); } else { // add the dynamic WebGrid to the body element.parent().parent().find(".file").append(d.Data); element.parent().parent().find(".pagination").empty(); element.parent().parent().find(".pagination").show(); element.parent().parent().find(".pagination").append(paging(1, d.Count, 5)); pagingEvent(); } } }); //$("#uploadFile").show(); //$("#uploadButton").show(); return false; }); }); </code></pre> <p>I'm trying to create an asynchronous search box, and it's working great with the exception of the edit link. Html.Actionlink throws the error, "The name 'Html' does not exist in the current context."</p> <p>VS suggests adding using System.Web.Mvc.Html but System.Web.Mvc.Html.ActionLink doesn't exists.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload