1

I am working on MVC. Currently my scenario is that when I save data from bootstrap modal popup it saves perfectly. When I open it for the second time, the values previously saved shows up in the modal popup. The model called in the bootstrap is filled with previous values when opened for the second time.

Is there any way to clear it when the modal closes after saving the data. So that when I opens again it would load the fresh data.

Below is the code for the action method

    [HttpPost]

    public ActionResult Savenfo(int Id, string comment, byte Status, string Code, string Rev, string Email, string Phone)
    {

        var form = objForm.Get(Id);
        if (form != null)
        {
            if (CurrentUserTicket.Dval!= form.DId)
                return new UnauthorizedActionResult();

            form.Comment = comment;
            form.Status = Status;
            form.Code = Code;
            form.Email= Email;
            form.Phone= Phone;
            form.Rev = Rev;
            objForm.Update(form);

            return new AjaxActionResponse(true, "Information has been saved.");

        }

        return new AjaxActionResponse(false, "The specified Information does not exist.");
    }
MaxPayne999
  • 184
  • 1
  • 2
  • 10

3 Answers3

1

You can try

  $(".modalClass").html("");
Vaidehi Hirani
  • 266
  • 3
  • 9
0

I recommend you to use ViewModel for binding data to view. So you can use ModelState.Clear() method to clear model after saving data.

You need to use this in your controller post method.

[HttpPost]
public ActionResult InsertData(ViewModel model)
{
    ModelState.Clear();
    model = new ViewModel();

    return View(model);
}
Rahul Nikate
  • 6,192
  • 5
  • 42
  • 54
0

You should clear your modal div html because you are re-generating the modal from partial view. Below is the code to remove modal element.

$('.modalclass').remove();
Sanjay Gupta
  • 186
  • 2
  • 11