vivid
vivid

Reputation: 1145

Calling a controller action MVC5

Ok so I got action that is in controller and code is:

[HttpPost]
public ActionResult SaveRow(int? id)
{
    //some db operations.
    return RedirectToAction("Index");
}

and in view I got

@Html.ActionLink(Translation.Accept, "SaveRow", new { id = item.New.RecId })

I got error 404 when I click button is possible to run this action without redirecting to url /SaveRow/ ? Maybe this button is used wrong I'm new in mvc5 so be patient.

Upvotes: 2

Views: 996

Answers (1)

Neel
Neel

Reputation: 11741

As documented here :-

2.An hyperlink or anchor tag that points to an action will ALWAYS be an HttpGet.

Try below code putting GET, as by default it takes [HttpGet] so remove [HttpPost] attribute

[HttpGet]
public ActionResult SaveRow(int? id)
{
    //some db operations.
    return RedirectToAction("Index");
}

and as an ideal design of MVC I would suggest you to use @Html.BeginForm to access pertiular POST call of edit functionailty

Upvotes: 5

Related Questions