使用ASP.NET MVC,我想調用控制器的按鈕在JQuery上的動作。如何調用按鈕的動作點擊從JQuery
控制器:
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
public ActionResult PersonInfo(string name, string city)
{
// other code for assign ViewData
return View();
}
}
我有兩個文本框,在Index.chtml頁面一個按鈕。我想要顯示Url,如'http://localhost:2526/PersonName'。對於城市我想要可選的參數並且不想在Url中。所以,我映射如下路線:
routes.MapRoute(
"Default", // Route name
"",
new { controller = "Home", action = "Index" } // Parameter defaults
);
routes.MapRoute(
"PersonInfo", // Route name
"{name}", // URL with parameters
new { controller = "Home", action = "PersonInfo", name= "" , city = ""} // Parameter defaults
從瀏覽器,如果我輸入網址,如「http://localhot:2526/John」然後PersonInfo視圖顯示成功。
我訪問link相關我的問題。但我也想傳遞參數。
任何人都可以幫我我怎樣才能調用按鈕點擊從JQuery的行動。
我試着用你的解決方案,但在我的情況下,它給了我'localhost:2526 /?name = John'在瀏覽器和頁面不重定向到personInfo視圖。請看我的路線圖(第二個)。我想傳遞兩個參數,並且只需要一個參數在路徑路徑中顯示。 –
它不適合使用映射來顯示只有一個參數,它更好地發佈您的參數使用窗體並顯示您想要在查詢字符串中的參數,換句話說,您可以將您的窗體發佈到MyController/MyAction?parameterToSend = value – 1AmirJalali
你能爲我提供案例嗎?我應該在路線圖和JQuery呼叫中採取哪些行動? –