T4MVC和Ajax方法与参数 [英] T4MVC and Ajax method with parameter

查看:111
本文介绍了T4MVC和Ajax方法与参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想T4MVC应用到我的项目。我说,我有一个AJAX搜索框,它会调用主页/ SEARCHQUERY行动这需要一个串Q作为参数。我如何写行T4MVC?

从Ajax.BeginForm(SEARCHQUERY,家,...
要Ajax.BeginForm(MVC.Home.SearchQuery(???)...

.cshtml文件

  @using(Ajax.BeginForm(SEARCHQUERY,家,/ *< -----转换为T4MVC这里* /
        新AjaxOptions {
            LoadingElementId =loadingGif
            的onSuccess =parseResults
            onFailure处=searchFailed
        })){
    <输入类型=文本名称=Q/>
    <输入类型=提交值=搜索/>
    < IMG ID =loadingGif的风格=显示:无SRC =@ Url.Content(〜/内容/图像/ loading.gif)/>
}< D​​IV ID =的SearchResult的风格=显示:表>< / DIV>


解决方案

是从表单的输入提交的,所以你可以只写

  @using(Ajax.BeginForm(MVC.Home.SearchQuery()
        新AjaxOptions {
            LoadingElementId =loadingGif
            的onSuccess =parseResults
            onFailure处=searchFailed
        })){
    <输入类型=文本名称=Q/>
    <输入类型=提交值=搜索/>
    < IMG ID =loadingGif的风格=显示:无SRC =@ Url.Content(〜/内容/图像/ loading.gif)/>
}

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>

解决方案

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

这篇关于T4MVC和Ajax方法与参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆