0

When I create a new record, I'm trying to redirect to the edit page with this.

return RedirectToAction("Edit", "Organization", new { OrgId = organization.OrgId });

However, the result is this.

http://localhost:1626/Organization/Edit?OrgId=5

when it should be

http://localhost:1626/Organization/Edit/5

Why is this?

3 Answers 3

1

The default route pattern for the default route registration is "{controller}/{action}/{id}", So if you want a url with that strucutre, you may rename your action method parameter name to Id

public ActionResult Edit(int id)
{
   // to do  : Return something
}

Another option is to use Attribute routing and specify this route pattern for the action method with your existing parameter (OrgId)

[Route("Organization/Edit/{OrgId}")]
public ActionResult Edit(int OrgId)
{
   // to do  : Return something
}
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, I was just being slow on this saturday morning.I'll give you the check mark when it lets me.
1

You have to change your route map, which might look like this currently

"{controller}/{action}/{id}"

to "{controller}/{action}/{OrgId}"

For further info: http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/asp-net-mvc-routing-overview-cs

Comments

-1

If you haven't changed your route table values,

Then you should change your action parameter to id instead of OrgId,

Or you should change your route table values from

{controller}/{action}/{id}

to

{controller}/{action}/{OrgId}

Comments

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.