Sai Avinash
Sai Avinash

Reputation: 4753

How to reload my drop down after the Ajax request

I am working on a ASP.net MVC 2.0 Application in C#.

I am using Ajax.beginForm() to make Postbacks / Ajax requests.

I n my page, i have a drop down and submit button. The drop down consists of list of users whose status is 0 .

When ever a particular user is selected and clicked on submit and his status will updated to 1.

So , after the Sucessful Ajax request i am calling a call back function to raise a alert that user status is sucessfully updated.

But, the problem is even though the user status is updated to 1, it still present in dropdown..since it is a partial update.

Now, my problem is how can i rebind the dropdown? Please help.

Upvotes: 0

Views: 654

Answers (1)

Emad Feiz
Emad Feiz

Reputation: 1575

you can reload your drop down by make an new ajax request, to recieve current users with status of 0, after successful post.

or use jquery to dyamically remove selected user from drop down list.

or you can put your ajax form in a partial view and re render it after ajax post, and update your ajax form completely:

[HttpPost]
Public ActionResult Post(...)
{
//do somethings

return Partial("_YourAjaxFormPartialView");
}

and in your Ajax.BeginForm(), use AjaxOptions to specify where area you want to update:

<div id="formContainer">
@using (Ajax.BeginForm("PostAction", "Home", 
    new AjaxOptions() {
        UpdateTargetId = "formContainer",
        OnSuccess = "alert('success')"
    })) 
</div>

Upvotes: 1

Related Questions