Home > DeveloperSection > Forums > How to submit web grid in asp.net mvc?
Goti Bandu

Total Post:119

Points:835
Posted on    October-11-2014 12:14 AM

 ASP.NET MVC ASP.Net  ASP.NET MVC 
Ratings:


 1 Reply(s)
 858  View(s)
Rate this:
I am trying to use a WebGrid to display some data, this is fine but I also want to add a column with a submit button that passes back an id from the model. here is my grid code.

       @{var grid = new WebGrid(source: Model);}

   <div>

        <h2>Multi User Login</h2>

 

        @using (Html.BeginForm())

        {

            @grid.GetHtml(columns: grid.Columns(

            grid.Column("CompanyName"),

            grid.Column("Address"),

            grid.Column(format: @<input type="submit" name="@item.idAddress" value = "select" />)))

 

 

        }

 

</div>

I have tried a number of ways to return the idAddress to the controller post method without any luck. How can I do this?

 



Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    October-11-2014 12:15 AM

How about using an ActionLink instead, if the only thing you want is the ID?

@{var grid = new WebGrid(source: Model);}

<div>

   <h2>Multi User Login</h2>

   @using (Html.BeginForm())

   {

      @grid.GetHtml(columns: grid.Columns(

         grid.Column("CompanyName"),

         grid.Column("Address"),

         grid.Column(format: (item) => Html.ActionLink("Click me", "MyAction", new { Id = item.idAddress}))

      ))

   }

</div>


Don't want to miss updates? Please click the below button!

Follow MindStick