python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
create attribute in mvc 5

How to create Attribute in MVC 5

Hello everyone, I'm going to share the steps for how to create attributes in mvc applications which are given below in details.

Table of Contents

Step 1. First create a class and inherit the FilterAttribute class or Attribute.
Step 2. Add the class name as attribute on tap on controller as well as actions method. 

In the below example you can seen the IsValidUser is class name as well as attribute name on controller or action methods.


Step1 : Here IsValidUser is a model class which inherited to filter attribute and its work like attribute.


namespace WebApplication1.Models
{
    public class IsValidUser : FilterAttribute
    {
        // here declaring constructor without parameter.
        public IsValidUser()
        {           
        }
    }

}


Step2 : This is controller class and here IsValidUser class use like attribute on top of the account controller or login action mrthod.

namespace WebApplication1.Controllers
{
    [IsValidUser]
    public class AccountController : Controller
    {    
        [IsValidUser]
        public ActionResult Login(string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;
            return View();
        }
    }
}


ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions