내가 질문했습니다 :전화 여러 컨트롤러 방법
이내가 다른 경로에서보기에서 여러 컨트롤러의 메소드를 호출 할 수있는 방법이 있는지 알고 싶습니다을 나는 설명 할 것이다 :
나는 "기본"노선과 내가 만든 새 사용할 :
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "TranslateText",
url: "{controller}/{action}/{stringToTranslate}/{from}/{to}",
defaults: new { controller = "Translation", action = "TranslateText", stringToTranslate = "", from = "", to = "" }
);
내가 기본 경로를 사용하고 나의보기에 여러 항목을 가지고,하지만 난 "은을 사용하고 하나가 TranslateText "경로.
난 그런 뷰에 전화 해요 :
<legend id="UploadCVLabel" style="color: #FF6600;">@(Url.Action("TranslateText", "Translation", "Upload your CV (Drag & Drop)", "en", "de" };))
</legend>
그리고 내 컨트롤러에서
는, 여기에 방법의 서명입니다 : 공공 JsonResult TranslateText (문자열 stringToTranslate = "", 문자열 inputLangCode = " en ", 문자열 outputLangCode ="fr ")"DefaultText "경로 앞에"TranslateText "경로를 넣을 때 동일한보기에서 둘 다 호출하는 방법이 있는지 알고 싶습니다. , 매개 변수없이 "TranslateText"메소드 만 호출하고 빈 JSON을 리턴합니다. 반대쪽 ("TranslateText"경로 이전의 "Default")을 수행하면 마지막 경로 ("TranslateText")를 호출하지 않습니다.
감사
PS :
@(Url.Action("TranslateText", "Translation", new {stringToTranslate = "Upload your CV (Drag & Drop)", from = "en", to = "de" }))
변경 메소드 서명 : 나는 당신이() 구문을 사용 다음 Url.Action에 오류가있는 MVC의 세계 :
번역보기 대신에 "/ Translation/TranslateText? stringToTranslate = 업로드 % 20your % 20CV % 20 (드래그 % 20 % 26 % 20Drop) & from = en & to = de" "TranslateText"경로를 "Default"앞에두면 디버그됩니다 ... – user1841787
편집 내용을 확인하십시오 – Dima
이 중 하나가 작동하지 않습니다 ...하지만 기본 경로를 먼저 설정하고 "@ (Html.Action ("TranslateText ","번역 ", 새로운 {stringToTranslate ="CV (드래그 앤 드롭) 업로드 ", ="en "에서 = "en"에서 to = "de"로 변환하는 대신 "@ (Url.Action ("TranslateText ","번역 ", 새 {stringToTranslate ="이력 업로드 (끌어서 놓기) "}))"번역을 제공하지만 HTML 태그 형식의 전체 페이지를 그래픽으로 렌더링하지 않습니다. 어떻게 수정합니까? – user1841787