Hi @Charlotte Garcia,
How is the code in your "Details" action written?
If you want to return a view, you need to createDetails.cshtml
.
Below is my test for your reference.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Custom route
routes.MapRoute(
name: "CustomRoute",
url: "products/{category}/{id}",
defaults: new { controller = "Products", action = "Details", id = UrlParameter.Optional }
);
}
Controller
public class ProductsController : Controller
{
Test1 test1 = new Test1();
public ActionResult Details(string category,int id)
{
test1.Id = id;
test1.category= category;
return View(test1);
}
}
Cshtml
@model MvcRazor.Models.Test1
@{
ViewBag.Title = "Details";
}
<h2>Details</h2>
<div>
<h4>Test1</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.category)
</dt>
<dd>
@Html.DisplayFor(model => model.category)
</dd>
</dl>
</div>
<p>
@Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |
@Html.ActionLink("Back to List", "Index")
</p>
public class Test1
{
public int Id { get; set; }
public string category { get; set; }
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.