【发布时间】: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