0

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?

2 Answers 2

3

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

[NonAction]
public ActionResult Edit()
{
}

private ActionResult Edit()
{
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, works with private, but I cannot find [NoAction] attribute? The type or namespace name 'NoAction' could not be found (are you missing a using directive or an assembly reference?)
@Willy my bad, it's called NonAction
Should I placed NonAction in Edit POST Action too?
@Willy yes, it's better you put it on both actions, so that POST edit action will not be invoked
1

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.

2 Comments

Is there any reason why do you use private instead of [NonAction]?
It is simple way to avoid using attributes to restrict accessing the action method. Using 'private' is better way then 'NonAction'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.