2012-10-27 5 views
0

내 검색 페이지에는 많은 매개 변수가 있으며이 페이지에는 현재 검색을위한 몇 가지 필터가 있습니다.
단지 내 경로의 일부 값을 변경하고 싶습니다.현재 경로의 일부 값만 변경하십시오.

예 :

HTML :

@using (Html.BeginForm("action", "controller", FormMethod.Post)) 
{ 
    @Html.DropDownListFor(m => m.Color, Model.Colors) 
    @Html.DropDownListFor(m => m.Price, Model.Prices) 
    <input type="submit" value="Search" /> 

} 

컨트롤러 :

내 검색 페이지에서
http://www.example.com/{controller}/{action}/{brand}/{model}/{color}/{price} 

나는 색상과 가격을 변경할 수있는 형태를 가지고

[HttpPost] 
public ActionResult Action(SearchModel search) 
{ 
    //I can get the Price and Color 
    string color = search.Color; 
    string price = search.Price; 

    //Now I want to get the values of brand and model 

    return RedirectToRoute("Action",new 
    { 
     controller = "Controller", 
     action = "Action", 
     color = color, 
     price = price, 
     brand = ????, 
     model = ???? 
    }); 

} 

남 왜 대신 QueryString을에 넣어하지

감사

+0

정확하게 원하지 않는 것은 무엇입니까? 숨겨진 필드? 검색 매개 변수 인 경우 사용자에게 표시되어야합니다. 또는 사용자 입력이 검색을 위해 전송 될 매개 변수를 변경할 수있는 경우입니까? – nieve

+0

안녕하세요. 컨트롤러에서 모델과 브랜드 값을 잡아 내고 싶습니다 (이 예제에서). 사용자 입력은 색상 및 가격 값만 변경합니다. – vpascoal

답변

0

\ : 예 검색이보다 더 많은 매개 변수가 ... 나는 숨겨진 필드에 넣어와 모델로 보내 싶지 않아? 그런 다음 다음과 같이합니다 :

http://www.example.com/something.aspx?color=red&price=100

그런 다음 당신은 당신이 원하는 픽업 나머지를 무시하고 순서는 중요하지 않습니다 수 있습니다.

호프가이 질문에 답변하기를 바랍니다. 정말로 솔직하게 이해하지 못했습니다.

+0

자신을 명확히하지 않았지만 답이 내 경로와 일치하지 않으면 죄송합니다. http://www.example.com/ {컨트롤러}/{액션}/{브랜드}/{모델}/{색상}/{ 가격} 기본적으로 사용자가 양식을 제출하면 사용자가 색상 및 가격의 새 값으로 URL로 리디렉션되고 브랜드 및 모델의 값을 유지합니다. – vpascoal

0

해결책을 찾았습니다.

나는이 작업을 수행해야합니다

@using (Html.BeginForm("action", 
         "controller", 
         new { brand = ViewContext.RouteData.Values["brand"], 
          model = ViewContext.RouteData.Values["model"] }, 
          FormMethod.Post)) 
{ 
    @Html.DropDownListFor(m => m.Color, Model.Colors) 
    @Html.DropDownListFor(m => m.Price, Model.Prices) 
    <input type="submit" value="Search" /> 

} 

을 그런 다음 컨트롤러 : 사람이 다른 해결책을 알고

[HttpPost] 
public ActionResult Action(SearchModel search) 
{ 

    return RedirectToRoute("Action",new 
    { 
     controller = "Controller", 
     action = "Action", 
     color = search.Color, 
     price = search.Price, 
     brand = search.Brand, 
     model = search.Model 
    }); 

} 

경우 알려 주시기 바랍니다. 감사합니다.

관련 문제