【问题标题】:Load data from SQL to Kendo UI DropDownList将数据从 SQL 加载到 Kendo UI DropDownList
【发布时间】:2015-06-09 12:43:50
【问题描述】:

我正在学习如何在用户单击 Kendo 按钮时调用服务器端函数。

我从这个主题阅读Call a server side MVC action on the click of a Kendo UI button

----这是原帖----

按钮是最新版本的 Kendo UI(上周)中的新功能。它不直接支持您正在寻找的内容,但可以像这样完成类似的事情:

@(Html.Kendo().Button()
.Name("textButton")
.Content("Text button")
.HtmlAttributes( new {type = "button"} )
.Events(ev => ev.Click("onClick")))

然后一个类似这样的JS函数:

function onClick(){
    $.ajax({
        url: '/controller/action'
        data: { // data here }
    }).done(function(result){
        // do something with the result
    }).fail(function() { // handle failure });
}

-----结束原帖------------

有人可以解释更多关于这个例子或解释更详细的例子吗? - 我不明白什么是数据,我们真的需要在 .done 中编写代码并失败吗?

这是我的看法:

@(Html.Kendo().Button()
    .Name("textButton")
    .Content("Text button")
    .HtmlAttributes( new {type = "button"})
    .Events(ev => ev.Click("onClick"))
)

这是我的 JS 函数

function onClick(){
    $.ajax({
    url: '/Home/GetView'
    data: { // data here }
    })
    .done(function(result){// do something with the result
    })
    .fail(function() { // handle failure });
}

这是我的控制器

namespace KendoMVCWrappers.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Kloon test Kendo UI ASP.NET MVC application by Pham Thai Son";

            return View();            
        }

        private JsonResult GetView(DataSourceRequest request)
        {
            return Json(GetData().ToDataSourceResult(request));
        }    
    }
}

【问题讨论】:

  • 在 ajax 函数中,'data' 是您要发送给控制器的内容。想象一下:data: { id: 99, code: 'test' }和你的控制器方法:public ActionResult Index(string id, string code) - 注意:我不明白问题的标题与问题本身有什么关系

标签: asp.net-mvc button kendo-ui server


【解决方案1】:

Kendo 允许您使用 JS 或 Razor 填充他们的小部件。我个人使用 Razor,但两者都使用过。剑道示例有时只显示其中一个。至于在单击 Kendo 按钮时调用函数,您不必在 .done 和 .fail 函数中添加任何内容,但 .done 或 success 是您可以放置​​函数以在单击按钮后填充下拉列表的位置。 .data 保存首先调用 onClick 函数返回的数据,并且 .done 和 .fail 允许您根据成功或失败来处理它。

您想知道如何按照标题的建议填充下拉菜单,还是希望解释他们的示例?

【讨论】:

    猜你喜欢
    • 2015-03-28
    • 2013-09-17
    • 1970-01-01
    • 2013-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-05
    • 1970-01-01
    相关资源
    最近更新 更多