Willy
Willy

Reputation: 1729

Temporary Disable Edit Action in ASP.NET MVC without Delete Its Action and View

I've got a request from customer to disable edit function on a survey module, but this still unclear. For temporary, it should be removed from view so, user cannot edit the survey.

So, I removed the edit button on the Index view, but I can still access the edit page through the address bar, for example: http://localhost:1306/Survey/Edit/1.

I cannot delete the Edit Action and Edit View, because the requirement is still unclear. Is there any way to handle this case?

Upvotes: 0

Views: 380

Answers (2)

Vsevolod Goloviznin
Vsevolod Goloviznin

Reputation: 12334

You can use NonAction attribute or make the method private, both solutions will work:

[NonAction]
public ActionResult Edit()
{
}

private ActionResult Edit()
{
}

Upvotes: 3

Aravindan
Aravindan

Reputation: 855

By using the Non Action method you can able to achive this like

public ActionResult Edit()
{
     // Your Code for doing someThing
}

Instead of the above one please use the below code.

private ActionResult Edit()
{
   // Your Code for doing someThing
}

If you use like this means you will not able to access the Edit action method.

Upvotes: 1

Related Questions