Search code examples
jqueryasp.net-mvcpartial-viewsajaxform

Unable to rebind the values of controls in MVC partial view


Below is the AJAX call that i am using to render a partial view

$.ajax({
    url: '/apps/Applications',
    dataType: 'html',
    contentType: 'application/x-www-form-urlencoded;charset=utf-8',
    type: 'post',
    data: $('#TaskList').serialize()
    //data: $('#form_' + id).serialize()
    //data: { appID: ID }
}).success(function (result) {
    $('#OpenApplications').show().append('<div class="tab-pane active" id="subnav_' + id + '" >' + result + '</div>');
}).error(function (xhr, status) {
    alert(status);
});

And my partialview has control as

@Html.TextBoxFor(model => model.Application.ID, new { id = "appid"})

I am getting the value of Application.ID in the backend, but in front end the value is not binding to the control of application.ID.

below is the controller code

        data.TaskChanges = new TaskHistory(data.Application.ID, data.Application.InternalStatus, data.Application.Processor, data.Application.AssessorComments, data.Application.InternalNotes);
        // we create if empty
        if (data.OpenTasks == null)
        {
            data.OpenTasks = new Dictionary<int, string>();
        }
        // now we add if not present
        if (!data.OpenTasks.ContainsKey(data.Application.ID))
        {
            data.OpenTasks.Add(data.Application.ID, data.Application.PID);
        }

        return PartialView("OpenApplications", data);

Any help?


Solution

  • try using below line in controller method

    ModelState.Clear();