Set value for textbox in action
I have a Textbox rendered by an HtmlHelper
<%= Html.TextBox("CategoryTitle",Model.CategoryTitle) %>
I post to an action. In the action I manually change the value for CategoryTitle and need to display this new value to the user, but the original value from the post is taken.
public ActionResult Textboxer(CategoryViewModel model)
{
model.CategoryTitle = model.CategoryTitle + "val1" ;
return View("Textboxer", model);
}
I need to keep the default behaviour of the Textbox (getting red when invalid).I dont feel like writing my ow开发者_开发技巧n helper for it.
Is there an easier way?
ModelState["CategoryTitle"].Value =
new ValueProviderResult(NeededValue, NeededValue, CultureInfo.CurrentCulture);
The reason behind this, I believe, is that Html.TextBox re-use "saved" values from ModelState whenever possible.
精彩评论