좋아, 이건 내가 좋아하는 토론이다.ASP.NET MVC 단일보기로 다른 작업 논리를 처리하는 방법은 무엇입니까?
.../browse
.../brand/audi/a4
.../category/tail-lights-17
.../search?t=fog+lamp
나의 현재 솔루션은이 노선에 대해 서로 다른 행동과 뷰를 작성하는 것입니다 : 우리는 같은 경로를 가지고있다.
@if(Model.ShowCarSelection)
{
@Html.Partial("_CarSelection")
}
나는이 같은 시나리오를 처리 할 방법을 궁금해 모든 뷰는 부분보기로 제품을 나열하고 있지만 (내가 다른 부분도 다시이 문제를 처리 할 수있는 가정) 필터링이나 자동차 선택과 같은 몇 가지 차이점이 있습니다. 예를 들어, 다음과 같은 내용은 무엇입니까?
[HttpGet, Route("browse"), Route("/{make}/{model}"), Route("categorySlug")]
public ActionResult List(string make, string model, string categorySlug, int page = 1, string sort, string filter)
{
var listVM = new ListVM();
if(!string.IsNullOrEmpty(categorySlug))
listVM.Products = productService.GetByCategorySlug(categorySlug);
else if (!string.IsNullOrEmpty(make))
listVM.Products = productService.GetByMakeAndModel(make, model);
// other things like filtering, sorting, preparing car selection partial view model etc.
return View();
}
그러나 이것은 내가 슬프고 (나쁨) 느끼게 만들 것입니다.
누구나 이와 비슷한 방법으로 나에게 지침을 줄 수 있습니까?
필터링 또는 검색 양식에 적합합니다. 'SearchCriteria' 모델로 POST 요청을 할 수는 있지만 카테고리 메뉴 링크 또는 특정 모델/모델 링크를 어떻게 생성하고 처리합니까? 모델을보기 위해 URL 세그먼트를 바인딩 할 수 있습니까? –