0

I am using asp mvc3.I want to learn how to make my Urls friendly. this is my repository layer:

public Section GetBySectionId(int sectionId)
{
    return context.Sections.Include("Groups").Include("Partners").Where(s => s.SectionId == sectionId).FirstOrDefault();
}

And this is the application layer:

public Section GetBySectionId(int sectionId)
{
    return sectionRepo.GetBySectionId(sectionId);
}

And this is the controller:

public ActionResult Details(int id)
{
    var section = Mapper.Map<SectionViewModel>(sectionApp.GetBySectionId(id));
    return View(section);
}

Now for example if I go to a section's details with id=3 the browser url would change to ~/Section/Details/3 but I want it to be ~/Section in persian/Details in persian/My section name.How can I do this.How to work with asp mvc routing?

Hamid Reza
  • 2,913
  • 9
  • 49
  • 76

1 Answers1

2

You should change in your Routing like this

routes.MapRoute(..., "{controller}/{action}/{id}", ...);

... and change it to something like this:

routes.MapRoute(..., "{controller}/{action}/{name}", ...);

Then have your action take the name instead of the ID:

Html.ActionLink(item.Name, "Details", new {item.Name})
Rajpurohit
  • 1,951
  • 2
  • 16
  • 19