带参数的T4MVC和Ajax方法

时间:2012-05-05 16:29:42

标签: asp.net-mvc t4mvc

我正在尝试将T4MVC应用于我的项目。说,我有一个ajax搜索框,它调用Home / SearchQuery动作,它接受一个字符串q作为参数。如何在T4MVC中写入该行?

来自Ajax.BeginForm(“SearchQuery”,“Home”,.... 到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>

2 个答案:

答案 0 :(得分:2)

您的q是从表单中的输入提交的,因此您只需编写

即可
@using (Ajax.BeginForm(MVC.Home.SearchQuery(),
        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")" />
}

答案 1 :(得分:1)

另一个可能的答案:重新生成模板

我知道这有点愚蠢,但我到这里只是因为我忘了用模板重新生成类(在重新生成模板之前可以访问带参数的新方法)。也许有人会觉得这很有用。