Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto generate action in controller MVC

I'm trying to use VS more efficiently, and I was looking for a way to generate a method automatically. For example, I know if you type foreach then press TAB twice it generates the skeleton code, so if I had a method like this:

[HttpPost]
public ActionResult CloseTicket()
{
    //do stuff
}

Is there a way of generating the 'skeleton code' so I don't have to manually type it out. I looked into method stubs but they don't seem to apply to this.

like image 502
Frayt Avatar asked Apr 07 '15 16:04

Frayt


People also ask

What is ActionResult () in MVC?

An action result is what a controller action returns in response to a browser request. The ASP.NET MVC framework supports several types of action results including: ViewResult - Represents HTML and markup. EmptyResult - Represents no result.

What is HTML ActionLink in MVC?

Html. ActionLink creates a hyperlink on a view page and the user clicks it to navigate to a new URL. It does not link to a view directly, rather it links to a controller's action.

What is the use of NonAction attribute in MVC?

The NonAction attribute is used when we want a public method in a controller but do not want to treat it as an action method. An action method is a public method in a controller that can be invoked using a URL. So, by default, if we have any public method in a controller then it can be invoked using a URL request.


1 Answers

There are built-in snippets in Visual Studio to help with this:

mvcaction4

inserts:

public ActionResult Action()
{
    return View();
}

And

mvcpostaction4

Inserts

[HttpPost]
public ActionResult Action()
{
    return View();
}
like image 99
DLeh Avatar answered Sep 28 '22 17:09

DLeh