简体   繁体   English

如何返回HTML并在带有YUI3的客户端上使用它

[英]How to return HTML and use it on the client with YUI3

I am using ASP.NET MVC3 and YUI3 . 我正在使用ASP.NET MVC3YUI3 I have a button on my view. 我的视图上有一个按钮。 When clicked it does an AJAX call to my controller's action method. 单击后,它将对我的控制器的操作方法进行AJAX调用。 This method returns HTML and then I need to take this HTML and set the contents of an HTML control to the returned HTML. 此方法返回HTML,然后我需要获取此HTML并将HTML控件的内容设置为返回的HTML。

I have the following in jQuery which works: 我在jQuery中具有以下功能:

$(document).ready(function () {
     $('#VerifyButton').click(function () {
          $.ajax(
          {
               type: "POST",
               url: "/Server/GetChangeIncidentDetails",
               data: { changeIncidentNumber: $('#ChangeIncidentNumber').val() },
               dataType: "html",
               success: function (result) {
                    var domElement = $(result); // create element from html
                    $("#changeImDetails").html(domElement); // append to end of list
               }
          });
     });
});

How would I do the exact same with YUI3? 如何使用YUI3完全相同? I have the following but I am not sure if I am on the right track? 我有以下内容,但是我不确定自己是否走对了?

YUI().use('event', 'node', 'io', function (Y) {
     Y.one('#VerifyButton').on('click', function (e) {
          alert('button clicked');
          e.preventDefault();
          alert(Y.one('#ChangeIncidentNumber').get('value'));
          var data = { changeIncidentNumber: Y.one('#ChangeIncidentNumber').get('value') };
          Y.io('/Server/GetChangeIncidentDetails', {
               method: 'POST',
               data: data,
               on: {
                    success: function (id, result) {
                         //var json = Y.JSON.parse(result.responseText);
                         //Y.one('#Title').set('value', json.Title);
                         alert(result);
                    }
               }
          });
     });
});

My action method just returns a partial view: 我的操作方法只是返回局部视图:

return PartialView("ChangeInformation", viewModel);

I managed to do this: 我设法做到了:

success: function (id, result) {
     Y.one('#changeImDetails').setHTML(result.responseText);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM