I’m working on my project in MVC 3 and searching for a way, which can add this functionality to all my Html.TextboxFor:
When user type “foo” and submit form, in controller level I get it by model as “fuu” for example.
I need this feature to replace some Unicode characters by some others.
Let I show my code in View and Controller:
View:
@Html.TextBoxFor(model => model.Title) // user will type "foo", in TitleTexbox!
Controller:
[HttpPost]
public virtual ActionResult Create(MyModel model)
{
var x = model.Title;
//I need variable x have 'fuu' instead of 'foo', replaceing "o" by "u"
//...
}
Should I write an override for Html.TextboxFor?
as i understood from your code , you expect from your model to be ready(processed) when it passed to your controller action.and for accomplishing this the only way is using model-binding.
but this approach is limited to particular type/class/model/viewmodel or whatever you name it.
you can create your own modelBinder as:
and then you most register your Custom Model Binder in Global.asax
make change in your action like this:
good luck.