T4MVC and Ajax method with parameter

陌路散爱 提交于 2020-01-24 22:14:47

问题


I am trying to apply T4MVC to my project. Say, I have an ajax search box, it calls Home/SearchQuery action which takes in a string q as parameter. How do I write that line in T4MVC?

From Ajax.BeginForm("SearchQuery", "Home", .... To Ajax.BeginForm(MVC.Home.SearchQuery(???)...

.cshtml file

@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>

回答1:


Your q is submitted from the input in form, so you could just write

@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")" />
}



回答2:


Another possible answer: regenerate the template

I know it's a bit stupid, but I got here just because I forgot to regenerate the classes with the template (the new method with parameters is accessible before you regenerate the templates). Maybe someone will find this usefull.



来源:https://stackoverflow.com/questions/10463773/t4mvc-and-ajax-method-with-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!