This is a migrated thread and some comments may be shown as answers.

[Solved] Passing model from grid to controller on external submit button

6 Answers 264 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vaishali
Top achievements
Rank 1
Vaishali asked on 30 Jul 2012, 10:04 PM
I have a Telerik grid with template column which consist of Radio buttons - Approve and Deny. How can I assign all the data to grid and send the model object to controller on external Submit button action?

Thanks,
Vaishali

6 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 02 Aug 2012, 10:52 AM
Hi Vaishali,

I am not sure I clearly understand your questions. You want to update the model item for that particular row in the dataSource when you change the selection of the Radio button? What exactly do you mean by "send the model object to controller on external Submit button action" ?

Kind regards,
Petur Subev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Vaishali
Top achievements
Rank 1
answered on 02 Aug 2012, 02:02 PM
Hi Petur,
You are right, I want to update the model item for that particular row in the dataSource when you change the selection of the Radio button?
So the view is strongly typed with one of the complex object, which provides datasource to render the grid. I have Submit Button at the end of the page, when user clicks on submit I want to send the complex object back to controller including user's radio button selection.
But the object is null when it comes back to controller.
here is the code -

<% Html.Telerik().Grid(Model.idrequest)

.Name("IdRequest")

.DataKeys(dataKeys =>

{ dataKeys.Add(r => r.RequestDetailsId).RouteKey(

"RequestDetailsId");

}

)

.Columns(columns =>

{

columns.Bound(r => r.RequestDetailsId);

columns.Bound(r => r.EmpId);

columns.Bound(r => r.Name);

columns.Bound(r => r.Email);

columns.Bound(r => r.ADSId);

columns.Bound(r => r.Action);

columns.Bound(r => r.Role);

if (columns.Bound(r => r.Action).Equals("Suspend"))

{

columns.Bound(r => r.SuspensionDate).Format(

"{0:MM/dd/yyyy}").Width(100);

columns.Bound(r => r.SuspensionReason);

}

if (Model.idrequest[0].Action == "Reactivate")

columns.Bound(r => r.ReactivationDate).Format(

"{0:MM/dd/yyyy}").Width(100);

if (Model.idrequest[0].Action == "Delegate")

{

columns.Bound(r => r.DelegateOwner);

columns.Bound(r => r.DelegationStartDate).Format(

"{0:MM/dd/yyyy}").Width(100);

columns.Bound(r => r.DelegationEndDate).Format(

"{0:MM/dd/yyyy}").Width(100);

}

columns.Template(r =>

{

%>

<%

= Html.RadioButton(r.RequestDetailsId.ToString(), "true", false, new { @id = "yes_Approve", @group = "Approval", @class="Radio" })%><label for="yes_Approve">Approve</label>

<%

= Html.RadioButton(r.RequestDetailsId.ToString(), "false", false, new { @id = "no_Approve", @group = "Approval", @class = "Radio" })%><label for="no_Approve">Deny</label>

<%

}).Title(

"Approve");

columns.Template(r =>

{

%>

<%

= Html.Hidden("Approved", new { @id = "hfApprove", @class="hfA" })%>

<%

= Html.Hidden("RequestDetailsId", new { @id = "hfRDetailsId", @class="hfRD" })%>

<%

}).Hidden();

})

.Pageable(paging => paging.Enabled(

true).PageSize(10))

.KeyboardNavigation()

.Filterable(filtering => filtering.Enabled(

true))

.Sortable(sorting => sorting.Enabled(

true))

.Groupable(grouping => grouping.Enabled(

true))

.Resizable(resizing => resizing.Columns(

true))

.Render();

%>

<%

=Html.Telerik().ScriptRegistrar().OnDocumentReady(

"$('" + ".Radio').click(function check(){ var Index =$(this).closest('"+"tr'"+").prevAll('"+"tr'"+").length; alert(Index);"+

"var grid = $('" + "#IdRequest'" + "); var row = grid.children().children(1)[2].children[Index];" +

"if(this.id=='" + "yes_Approve'" + "){ $(row).find('" + "#Approved'" + ").val(true); $(row).find('" + "#RequestDetailsId'" + ").val(this.name);}" +

"else{ $(row).find('" + "#Approved'" + ").val(false); $(row).find('" + "#RequestDetailsId'" + ").val(this.name);}" +

"}); "

) %>

</div>

<div class="content">

<input type="submit" id="approveRequest" value="Submit" />

</div>
0
Petur Subev
Telerik team
answered on 07 Aug 2012, 11:14 AM
Hello Vaishali,

I am afraid that your question is not directly related to the Grid component but how to submit list of groups of radio buttons to a MVC controller action. Here are some links which you might need when dealing with the submit of a collection.
http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx 
http://weblogs.asp.net/nmarun/archive/2010/03/13/asp-net-mvc-2-model-binding-for-a-collection.aspx 


Kind Regards,
Petur Subev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Steven
Top achievements
Rank 1
answered on 27 Jan 2013, 08:07 PM
<Admin>
The use of inappropriate or offensive language is not permitted on our site. Insulting, threatening, and harassing comments will not be tolerated.

0
Steven
Top achievements
Rank 1
answered on 27 Jan 2013, 08:09 PM
<Admin>
The use of inappropriate or offensive language is not permitted on our site. Insulting, threatening, and harassing comments will not be tolerated.
0
Georgi Tunev
Telerik team
answered on 28 Jan 2013, 08:58 AM
Steven,

Please refrain from using offensive language in your postings.




Georgi Tunev
Technical Support Director
Telerik
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
Tags
Grid
Asked by
Vaishali
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Vaishali
Top achievements
Rank 1
Steven
Top achievements
Rank 1
Georgi Tunev
Telerik team
Share this question
or