0

I am new to MVC and have a simple Question.

This is my view:

@model EditWorkflowViewModel

@Html.TextBoxFor(m => m.Test, new { id = "txtbTest", @class = "form-control"})

<button class="btn btn-success" id="btnOk"><i class="fa fa-floppy-o"></i> Ok</button>

This is my Controller Action:

[HttpPost]
public ActionResult Edit(EditWorkflowViewModel viewModel)
{
    //... Code to persist the viewModel Data...

    viewModel.Test = "changed";

    if (Request.IsAjaxRequest())
        return PartialView("_Edit", viewModel);
    return View("_Edit", viewModel);
}

Why is the TextBox not updated with the Text "changed" after the Action was executed and how can i update the view in this case?

Thanks for Help

Boris
  • 41
  • 1
  • 6
  • 2
    Because the html helpers use the values from `ModelState` rather than your model properties if they exist. And because you method has a parameter for your model, its property values are added to `ModelState` by the `DefaultModelBinder` (refer [this answer](http://stackoverflow.com/questions/26654862/textboxfor-displaying-initial-value-not-the-value-updated-from-code/26664111#26664111) for a more detailed explanation) –  Nov 04 '15 at 09:14

1 Answers1

0

Thanks for your Answer Stephen.

Behaviour and Solution for this Problem are in the Link, posted by Stephen:

TextBoxFor displaying initial value, not the value updated from code

Community
  • 1
  • 1
Boris
  • 41
  • 1
  • 6