Custom ActionLink Column: Pass individual [UserId] instead of Static "1" value?

Apr 22, 2014 at 3:21 PM
I've created a Custom Column in Grid.MVC that is an ActionLink currently redirecting to a User Details - EDIT View by passing a static Id of "1".

How do I set the ActionLink to pass the individual UserId?
@using GridMvc.Html
@model IEnumerable<PROJECT.Models.Users>

@{
    ViewBag.Title = "View Users";
}

<div class="overflowPrevention">

    @*Images in Columns: https://gridmvc.codeplex.com/discussions/440977*@

    @Html.Grid(Model).Columns(columns =>
        {
            columns.Add().Encoded(false).Sanitized(false).SetWidth(30).RenderValueAs(o => @Html.CheckBox("checked", false));
            columns.Add(u => u.Id).Encoded(false).Sanitized(false).RenderValueAs(o => Html.ActionLink("Edit", "Edit", "UserManage", new { id = "1" }, null));
            
        }).AutoGenerateColumns()
</div>
Coordinator
Apr 26, 2014 at 5:37 AM
Hi,

try to use:
columns.Add(u => u.Id).Encoded(false).Sanitized(false).RenderValueAs(o => Html.ActionLink("Edit", "Edit", "UserManage", new { id =o.Id }, null));
Jun 10, 2014 at 7:47 PM
Bukharin,
I tried the code above and it works, but I need to conditionally style my data. It's italic or bold, depending on the type. I nested ActionLink inside a helper function and it give me raw html:
<a href="/TeklaWebClientMVC/Report/OpenPartFile?partName=CX001_3MZE0440607000002B&modelFolderPath=%5C%5CSTLMKCVSMSD2%5CMSDFiles1%5C90-002804-01-06_03_2014_07_03_14_515_AM&fileFormat=PDF">CX001_3MZE0440607000002B</a>

Do you have a way to accomplish this?

Thanks

Here's my code:
    <div >
    @helper RenderPartName(MSDReportedPart p, Request r)
    {
        if (r.OutputFormat == "PDF")
        {
            if (p.PartType == "Part")
            {
                
            <div>&nbsp&nbsp&nbsp <i>@Html.ActionLink(p.Name, "OpenPartFile", "Report", new { partName = p.Name, modelFolderPath = r.ModelPath, fileFormat = r.OutputFormat }, null).ToHtmlString()</i>

            </div>
            }
            else
            {
            <div><b>@Html.ActionLink(p.Name, "OpenPartFile", "Report", new { partName = p.Name, modelFolderPath = r.ModelPath, fileFormat = r.OutputFormat }, null).ToHtmlString()</b></div>
            }
        }
        else
        {
            if (p.PartType == "Part")
            {
            <div>&nbsp&nbsp&nbsp <i>@p.Name</i></div>
            }
            else
            {
            <div><b>@p.Name</b></div>
            }
        }
    }
    @helper RenderPartColumn(Request r, Log l)
    {

        <div  style="overflow-y: scroll; height:300px;">@*scrollable div*@
        @Html.Grid(Model.GetPartsByModelName(r.ModelName).OrderBy(x => x.Name)).Columns(columns =>
        {
            columns.Add(c => c.Name).Titled("Part Name").Encoded(false).Sanitized(false).Sortable(true).Filterable(true).RenderValueAs(v => RenderPartName(v, r).ToHtmlString());

            //code below works, but lose italic and bold style.  I would like to use helper function RenderPartName() above
            //columns.Add(c => c.Name).Titled("Part Name").Encoded(false).Sanitized(false).Sortable(true).Filterable(true).RenderValueAs(v => Html.ActionLink(v.Name, "OpenPartFile", "Report", new { partName = v.Name, modelFolderPath = r.ModelPath, fileFormat = r.OutputFormat }, null));
            
            columns.Add(c => c.PartType).Titled("Type").Sortable(true).Filterable(true);

        })
        </div>

    }
    @Html.Grid(Model.LogByOrderNumber()).Columns(columns =>
    {
        columns.Add(c => c.Request.ModelName).Encoded(false).Titled("Model Name").Sortable(true);
        columns.Add(c => c.Request.ProjectName).Encoded(false).Titled("Project Name").Sortable(true);
        columns.Add(c => c.Request.OrderNumber).Encoded(false).Sanitized(false).Titled("Parts Information").RenderValueAs(a => RenderPartColumn(a.Request, a.Log).ToHtmlString());

    }).WithPaging(20)
    </div>
Jun 10, 2014 at 8:21 PM
I got it working after I posted the question. All I did was remove ToHtmlString() after ActionLink(). It didn't work before because I didn't have Sanitized(false). I don't fully understand Sanitized(false). Here's the working code, in case somebody needs it:
    <div >
    @helper RenderPartName(MSDReportedPart p, Request r)
    {
        if (r.OutputFormat == "PDF")
        {
            if (p.PartType == "Part")
            {
                
            <div>&nbsp&nbsp&nbsp <i>@Html.ActionLink(p.Name, "OpenPartFile", "Report", new { partName = p.Name, modelFolderPath = r.ModelPath, fileFormat = r.OutputFormat }, null)</i>

            </div>
            }
            else
            {
            <div><b>@Html.ActionLink(p.Name, "OpenPartFile", "Report", new { partName = p.Name, modelFolderPath = r.ModelPath, fileFormat = r.OutputFormat }, null)</b></div>
            }
        }
        else
        {
            if (p.PartType == "Part")
            {
            <div>&nbsp&nbsp&nbsp <i>@p.Name</i></div>
            }
            else
            {
            <div><b>@p.Name</b></div>
            }
        }
    }
    @helper RenderPartColumn(Request r, Log l)
    {

        <div  style="overflow-y: scroll; height:300px;">@*scrollable div*@
        @Html.Grid(Model.GetPartsByModelName(r.ModelName).OrderBy(x => x.Name)).Columns(columns =>
        {
            columns.Add(c => c.Name).Titled("Part Name").Encoded(false).Sanitized(false).Sortable(true).Filterable(true).RenderValueAs(v => RenderPartName(v, r).ToHtmlString());
           
            columns.Add(c => c.PartType).Titled("Type").Sortable(true).Filterable(true);

        })
        </div>

    }
    @Html.Grid(Model.LogByOrderNumber()).Columns(columns =>
    {
        columns.Add(c => c.Request.ModelName).Encoded(false).Titled("Model Name").Sortable(true);
        columns.Add(c => c.Request.ProjectName).Encoded(false).Titled("Project Name").Sortable(true);
        columns.Add(c => c.Request.OrderNumber).Encoded(false).Sanitized(false).Titled("Parts Information").RenderValueAs(a => RenderPartColumn(a.Request, a.Log).ToHtmlString());

    }).WithPaging(20)
    </div>