问题
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