MVC - Column button pass first grid.row information instead the selected one.

Nov 29, 2013 at 8:12 AM
I have costumized a column grid with a button that sould pass row information to the controller.
My problem is that when the button is clicked the row information passed to the controller referes ALWAYS the first row and not the selected row.

This is my code:

@Html.Grid(Model).Columns(columns =>
   .RenderValueAs(o => MyButton(o)); ***See below

   columns.Add(o => o.NDG)

MyButton is:
@helper MyButton(RiepilogoOperazioniOggiXls R)
    Html.BeginForm("SendEmail", "Email", new { NDG = R.NDG, eMail = R.eMail }, FormMethod.Post);
<input type="submit" value="Send mail" name="btnEmail"  />
<label>@Html.DisplayFor(X => R.NDG)</label>

Controller code:
    public string SendEmail(String  NDG, string eMail) 
        string ObjM = "Mcv test " + NDG; -> this contains Always NDG of the first row of the grid not the selected.

        return "ok";
Can you help me?
Nov 29, 2013 at 12:58 PM
can you try some thing like
<a href="@Url.Action("SendEmail","Email", new {NDG = R.NDG, eMail = R.eMail, @class="send-mail" }) />


        $(function () {
            $(".send-mail").click(function (event) {
                var href = $(this).attr('href');
                    url: href, type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                        function (result) {

Dec 3, 2013 at 7:49 AM
Thanks bhushanvinay!
It works!