我想將T4MVC應用到我的項目。說,我有一個Ajax搜索框,它調用Home/SearchQuery操作,它接受一個字符串q作爲參數。我如何在T4MVC中編寫該行?T4MVC和Ajax方法與參數
從Ajax.BeginForm( 「SEARCHQUERY」, 「家」,.... 要Ajax.BeginForm(MVC.Home.SearchQuery(???)...
.cshtml文件
@using (Ajax.BeginForm("SearchQuery", "Home", /* <-----Convert to T4MVC Here */
new AjaxOptions {
LoadingElementId = "loadingGif",
OnSuccess = "parseResults",
OnFailure = "searchFailed"
})) {
<input type="text" name="q" />
<input type="submit" value="Search" />
<img id="loadingGif" style="display:none" src="@Url.Content("~/content/images/loading.gif")" />
}
<div id="searchResults" style="display: table"></div>
我不明白你的意思。因爲MVC.Home.SearchQuery()會給你一個語法錯誤,SearchQuery簽名有參數(字符串q),對嗎?像這樣... [OutputCache(NoStore = true,VaryByParam =「」,Duration = 0)] [AcceptVerbs(HttpVerbs.Post)] public virtual JsonResult SearchQuery(string q){ if(!Request.IsAjaxRequest() )返回null; .... //更多代碼 – Tom
那個簽名不匹配的語法錯誤(填充到字符串q中)正是我的問題所在。 – Tom
T4MVC總是產生一個沒有參數的重載,所以@archil建議應該工作。你有沒有嘗試過? –