MVC model does not update when data populated through jQuery

2 posts, 0 answers
  1. Ram
    Ram avatar
    3 posts
    Member since:
    Apr 2015

    Posted 03 Jun Link to this post

    I'm using a kendo grid popup editor. I have a custom template (partial view) for edit. I have a drop down and on change event, I'm populating a TextBox. The problem is when I am sending the model to the controller, the TextBox value is null. It's not updating the model with the populated value. Any idea why?

    @(Html.Kendo().DropDownListFor(w => w.AddressID)

    .DataTextField("Name")

    .DataValueField("AddressID")

    .DataSource(source =>{ source.Read(read =>{ read.Action("GetAddressType", "DataSource")

    .Data("filterAddressTypes");})

    .ServerFiltering(true);})

    .CascadeFrom("CodeIDAddressType")

    .Events(e => e.Change("addressSubType"))

    )

     

    @Html.TextBoxFor(model => model.AddressLine1)

    On an AJAX done function, I'm populating the value.
    $("#AddressLine1").val(response.AddressLine1)

    I can see the new value in the text box but when submitted, it sends null to the controller. If I enter the value in the AddressLine1 field instead of populating, it sends the entered value to the controller.

  2. Eyup
    Admin
    Eyup avatar
    3012 posts

    Posted 07 Jun Link to this post

    Hello Ram,

    To help the grid to "capture" the new value you've set manually using script, you can try using the following approach:
    http://www.telerik.com/forums/textbox-value-set-by-jquery-is-empty-on-save#Hb80Zx7l802iIjk_CUFC1A

    I hope this will prove helpful.

    Regards,
    Eyup
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top