开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜