jQuery的MVC +用户控件 [英] jQuery + MVC User Controls

查看:160
本文介绍了jQuery的MVC +用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的就是传递参数,这将更新div标签和渲染基于一个隐藏的用户控件有新数据的用户控制视图。我知道如何使用Ajax.Form()辅助方法,但传递参数和更新部分控制超出了我更新的div标签。我从来没有使用jQuery的,抬头就如何MVC中实现它的一些教程,但我已经打了太多的死角,需要一些帮助找出一个解决方案。我现在有这和需要进行扩展,以更新用户控制视图。

ASPX文件

 <表ID =formParams>
    <输入名称=textSearch1类型=文本/>
    <输入名称=textSearch2类型=文本/>
    <输入名称=为btnTest类型=提交的onclick =$得到('recordsForm')的onsubmit()。VALUE =点击我/>
< /表及GT;
<%使用(Ajax.Form(
            记录,
            搜索,
            空值,
            新AjaxOptions
            {
                UpdateTargetId =记载
                的onSuccess = @功能(发件人,参数){},
                列举HTTPMethod =GET
            },
            新{@id =recordsForm}))
        {
        }
    %GT;
    < D​​IV ID =记载>
        &所述; IMG SRC =&下;%= Url.Content(〜/内容/图像/ load.gif)%>中ALT =载入中.../>
    < / DIV>

ACSX文件

 <%=计算机[searchText1]的ToString()%>就是你输入的搜索。

控制器CS文件

 公众的ActionResult记录(字符串searchText1,串searchText2)
        {            计算机[searchText2] = searchText2 +停在jQuery的亚青吸吮
            计算机[searchText1] = searchText1;
            返回视图(史记);
        }


解决方案

我想通了..哇我所要做的就是纳入元素融入到阿贾克斯的形式而不是在一个单独的形式在它之外的。

What I'm trying to do is pass parameters to a user control view which will update a div tag and render the new data based on a hidden user control there. I know how to update a div tag using the Ajax.Form() Helper Method but passing parameters and updating the partial control is beyond me. I've never used jQuery and looked up some tutorials on how to implement it within mvc but I've hit too many dead ends and need some help figuring out a solution. What I currently have is this and need to extend it to update the user control view.

ASPX File

<form id="formParams">
    <input name="textSearch1" type="text" />
    <input name="textSearch2" type="text" />
    <input name="btnTest" type="submit" onclick="$get('recordsForm').onsubmit()" value="Click Me" />
</form>
<% using (Ajax.Form(
            "Records",
            "Search",
            null,
            new AjaxOptions
            {
                UpdateTargetId = "records",
                OnSuccess = @"function(sender, args){}",
                HttpMethod = "GET"
            },
            new { @id = "recordsForm" }))
        {
        } 
    %>
    <div id="records">
        <img src="<%= Url.Content("~/Content/Images/load.gif") %>" alt="loading..." />
    </div>

ACSX file

<%= ViewData["searchText1"].ToString()%> is the search you entered.

Controller CS File

public ActionResult Records(string searchText1, string searchText2)
        {

            ViewData["searchText2"] = searchText2 + " Stop sucking at jQuery Ayo";
            ViewData["searchText1"] = searchText1;


            return View("Records");


        }

解决方案

I figured it out.. wow all i had to do was incorporate the elements into the ajax form instead of having it in a separate form outside of it.

这篇关于jQuery的MVC +用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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