Can anybody please tell me why should I use NonAction? I mean say I have a form with several submit values: Update, Delete or Insert. Since all the submit buttons have the s
If you did not want to invoke some action methods then you have to mark it with a attribute [NonAction]
or by making it private
public ActionResult Index(){
return View();
}
[NonAction]
public ActionResult Countries(List<string>countries){
return View(countries);
}
you can copy the code and paste it and see the result.thanks
Reading Haack's Article
Any public method in a controller class is callable via URL.
Sometimes you may need to avoid this. For example, if you implement some interface and you may not want to call that public method you can mark as NonAction
public interface IEmployee
{
void Save(Employee e);
bool Validate(Employee e);
}
public class EmployeeController:Controller, IEmployee
{
public void Save(Employee e){
}
[NonAction]
public void Validate(Employee e){
}
}
It's an attribute which is used on the methods which are defined by public access modifiers. Actually MVC Framework treats all public methods as URLs but in case you don't want this then you have to decorate a method with the non action attribute. The same thing may be achieved by making the method private.
An example of NonAction Attribute is given below. http://yogeshdotnet.com/non-action-attribute-in-mvc/
NonAction attribute makes an action non accessible from the navigation bar. For example if you have an action which deletes items in database, you have to add the NonAction
attribute to make it not accessible by users.