mishrsud / so-view-model-bind-20869735

Stackoverflow question 20869735 how-to-bind-view-model-property-with-different-name

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Binding Alias Name to ViewModel Property

Stackoverflow question 20869735 how-to-bind-view-model-property-with-different-name

When you want to use it:

[ModelBinder(typeof(AliasModelBinder))]
public class FilterViewModel
{
    [BindAlias("someText")]
    public string FilterParameter { get; set; }
}

In html:

@* at least you dont write "someText" here again *@
@Html.Editor(Html.AliasNameFor(model => model.FilterParameter))
@Html.ValidationMessage(Html.AliasNameFor(model => model.FilterParameter))

Generated html output contains input element by using BindAlias and sets name attribute to "someText".

About

Stackoverflow question 20869735 how-to-bind-view-model-property-with-different-name


Languages

Language:C# 67.4%Language:JavaScript 30.4%Language:CSS 1.9%Language:ASP 0.3%