What is called this MVC function?

I recall the MVC function, which allows you to influence the original object, with which you can get the parameter values ​​for this method.

public ActionResult Foo([SomethingHere] int parameter)
{
    // do something with parameter

    return View();
}

In brackets "[SomethingHere]" will contain a member called "parameter", which MVC will then try to get from int. I forgot what is called this function and my google fu is apparently weak. What is called?

+4
source share
2 answers

A [Thing]is called an attribute. Attributes themselves do nothing, they simply provide metadata.

Using attributes, you can tell MVC to handle certain things other than their default values.

.

"" : ASP.NET MVC Preview 5 . [Bind].

MSDN : BindAttribute, ModelBinderAttribute.

+2

?

public class HomeCustomDataBinder : DefaultModelBinder
{
    public override object BindModel(
        ControllerContext controllerContext,
        ModelBindingContext bindingContext)
    {
        // Various things.
    }
}

public ActionResult Index(
    [ModelBinder(typeof(HomeCustomBinder))] HomePageModels home)
{
    // Various things.
}

. ASP.NET MVC Custom Model Binder .

0

Source: https://habr.com/ru/post/1619916/


All Articles