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

[Solved] Post multiple values from EditorTemplate

3 Answers 79 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.
JULIA
Top achievements
Rank 1
JULIA asked on 28 Jul 2010, 08:15 AM
Hello,

i have the following EditorTemplate.
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TumourResectionTypeViewModel>" %>
  
<%= Html.DropDownList( null, new SelectList( ( IEnumerable )ViewData["tumourResectionTypes"],
                                            "TumourResectionTypeId", "TypeName" ), new { style = "width: 50%;" } )%>
  
<%= Html.LabelFor( m => m.IsCured ) %>
<%= Html.CheckBoxFor( m => m.IsCured )  %>
  
<script type="text/javascript">
    var $dropdown = $('#TumourResectionType');
    $('<option/>', { text: '...', value: "" }).prependTo($dropdown);
    var $tr = $dropdown.closest('tr:has(form)');
    var grid = $tr.closest('.t-grid').data('tGrid');
    var dataItem = grid.dataItem($tr);
    $dropdown.val(dataItem.TumourResectionType ? dataItem.TumourResectionType.TumourResectionTypeId : "");
  
    var c = $tr.find("input[type=checkbox]:first");
    var l = $tr.find("label:first");
    if (dataItem.TumourResectionType.IsCured) {
        c.attr("checked", "checked");
    }
    else {
        c.removeAttr("checked");
    }
  
    $dropdown.change(function () {
        if ($(this).val() == 1) {
            l.show();
            c.show();            
        }
        else {
            l.hide();
            c.hide();
        }
    }).change();
</script>

The bool value for IsCured will never post. How can i achieve this goal?

Mit Update/Insert Action:
public ActionResult _Update( GridCommand command, int tumourResectionType, bool isCured = falseint id = 0 )

IsCured is always false.

Regards,
Timo

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 28 Jul 2010, 09:52 AM
Hello Timo,

The rendered checkbox sends its value to the server, but the IValueProvider does not catch it from the posted data. As you probably know the name property of the rendered checkbox (and all other HTML elements which has name property) should have the same value as the expected parameter of the Action. In other words if you render checkbox with name="IsCured", you need to have same parameter in the Action method:
public ActionResult ActionMethod(bool IsCured). In your case the parameter is named "isCured".

Greetings,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
JULIA
Top achievements
Rank 1
answered on 28 Jul 2010, 11:01 AM
I will open a ticket with a sample project.
0
Georgi Krustev
Telerik team
answered on 28 Jul 2010, 03:44 PM
Hello Timo,

Here is a quote of the answer which I send you in the support thread:

Thank you for contacting us.

ASP. NET MVC EditorFor HTML helper uses passed Lambda expression to get the property of the model for which it is created. In other words if you uses Html.CheckBoxFor(m => m.IsCured) the rendered inpu will have name property with "Employee.IsCured". Hence on the server you need to expect Employee object, not just IsCured parameter. In you case IValueProvider could not update Employee object (defined by Linq2SQL), that is why I am creating fake EmployeeFake object just for the test. Check the attached project for reference.

If you decide not to use CheckBoxFor (or other EditorFor extensions) method you can use separate parameters which represent Employee properties. Here is a code snippets showing what I mean:

[ASCX]:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Employee>" %>
 
<%= Html.CheckBox("isCured", Model.IsCured) %>

        [GridAction]
        public ActionResult UpdateOrder(int id, bool isCured)
        {
...

Let me know if this helps.

All the best,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
JULIA
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
JULIA
Top achievements
Rank 1
Share this question
or