시간표와 취항 구조가 같은 이름,하지만 diffrent 컨트롤러가 페이지, NaturalStones 페이지로 이동해야합니다. 나는이 문제를 해결할 수 없다.MVC 조치
도와주세요!
시간표와 취항 구조가 같은 이름,하지만 diffrent 컨트롤러가 페이지, NaturalStones 페이지로 이동해야합니다. 나는이 문제를 해결할 수 없다.MVC 조치
도와주세요!
라우팅 정보가 매우 정돈되어 있으므로 제공된 코드로 올바르게 작동해야합니다. 나는 당신이 어떤 컨트롤러를 사용하는지 혼란스러워했다고 생각합니다. 그래서
@Url.Action("Index", "Product", new { title = "mytitle", id = "myid" })
반환 라우팅이 제대로 제품 컨트롤러, 두 개의 매개 변수와 색인 작업에 대한 요청으로 인식 /en/products/mytitle-myid
. 반면
@Url.Action("Details", "NaturalStones", new { title = "mytitle", id = "myid" });
에
는 NaturalStones에 요청, 두 개의 매개 변수와 세부 작업으로 해석됩니다 /en/natural-stones/mytitle-myid
를 생성, 그것은 아마 당신이 사용하고자하는 하나입니다.
제품에 대해 title
및 id
을 제공하면 색인 작업이 다소 번거 롭습니다. 규칙에 따라 일반적으로 색인 작업은 항목 목록을 반환하므로 특정 ID에 대한 참조가 부적절한 것으로 보입니다. 당신은 당신의 경로를 변경하는 것이 좋습니다 :
routes.MapRoute(
name: "NaturalStonesDetails",
url: "{lang}/natural-stones/{title}-{id}",
defaults: new { lang = "en", controller = "NaturalStones", action = "Details" }
);
routes.MapRoute(
name: "ProductCategorieList",
url: "{lang}/products",
defaults: new { lang = "en", controller = "Product", action = "Index" }
);
한 후 다음과 같은 컨트롤러가 있습니다
public class ProductController : Controller
{
public ActionResult Index()
{
return View();
}
}
public class NaturalStonesController : Controller
{
public ActionResult Details(string title, string id)
{
return View();
}
}
을