clement
clement

Reputation: 4266

Controller's actions in c#

I'm making a basic app in MVC.

I have a edit page. That page is feed by the object ID.

public ActionResult Edit(int id)

When you see this edit page, a "Save" button is in the bottom.

<input type="submit" value="Save" />

So I made a second method that is called to perform changes in DB :

public void Edit(MyObject object)

I have troubles because they all have the same method name.

So how Can I rename the second method name (that receive the custom object)? The button must be linked again to the method that perform edition in DB...

Thanks !

Upvotes: 2

Views: 81

Answers (2)

Nick
Nick

Reputation: 4212

Try with it

    [HttpPost]
    public void Edit(MyObject object)

or

    [HttpPost]
    [ActionName("MyOverloadedName")]
    public void Edit(MyObject object)

Upvotes: 2

SLaks
SLaks

Reputation: 887453

There is nothing wrong with two actions that have the same name.
However, you should add [HttpPost] to the POST action.

Upvotes: 2

Related Questions