Quantcast
Channel: Code monkey CODE!! » Razor
Viewing all articles
Browse latest Browse all 3

MVCContrib grid ajax.actionlink in razor

$
0
0

The gridview from mvccontrib seems pretty happy in razor, here’s a little example to help you along. But when your looking to add ajax.actionlink you must of remeber to get you javascript to handle the action. Heres the code, pay attention to the new unobtrusive jquery. More on these as I discover the benefits :)

@model Entities.Products.Product
@using MvcContrib.UI.Grid;
@using MvcContrib.UI.Pager;
@using MvcContrib.Pagination;
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/index.js")" type="text/javascript"></script>
 
@{
    ViewBag.Title = Model.Name;
    Layout = "~/Views/Shared/SiteLayout.cshtml";
}
 
<h2>Partner @Model.Name</h2>
@{
    Html.Grid(Model.CreditCards).Columns(column =>
    {
        column.For(c => c.SortOrder).Named("Ordering");
        column.For(c => Html.ActionLink(c.Name, "details", "premiumpartners", 
new { id = c.Id }, new { })).Named("Name").DoNotEncode();
        column.For(c => c.SpecialOfferIframe).Named("Special Offer IFrame");
        column.For(c => Ajax.ActionLink(c.IsLive ? "True":"False", "toggleLive", 
"premiumpartners", new { id = c.Id },new AjaxOptions { InsertionMode = InsertionMode.Replace }, new { })).Named("IsLive").DoNotEncode();
        column.For(c => Html.ActionLink("Edit", "editproduct", "premiumpartners", new { id = c.Id }, new { })).Named("").DoNotEncode();
    }).Render();
 
 
}

Viewing all articles
Browse latest Browse all 3

Trending Articles