MVC 3 - Html.EditorFor seems to cache old values after $.ajax call

前端 未结 5 1857
一整个雨季
一整个雨季 2020-11-27 14:09

This is a follow on from the following question:

MVC 3 + $.ajax - response seems to be caching output from partial view

There is a detailed description of th

5条回答
  •  隐瞒了意图╮
    2020-11-27 14:55

    There is no caching involved here. It's just how HTML helper work. They first look at the ModelState when binding their values and then in the model. So if you intend to modify any of the POSTed values inside your controller action make sure you remove them from the model state first:

    [HttpPost]
    public virtual ActionResult AjaxCreate(Transaction transaction)
    {
        if (ModelState.IsValid)
        {
            service.InsertOrUpdate(transaction);
            service.Save();
        }
        service.ChosenCostCentreId = transaction.IdCostCentre;
        TransactionViewModel viewModel = new TransactionViewModel();
        ModelState.Remove("Transaction");
        viewModel.Transaction = new Transaction();
        ModelState.Remove("CostCentre");
        viewModel.CostCentre = service.ChosenCostCentre;
        ...
    
        return PartialView("_Create", viewModel);
    }
    

提交回复
热议问题