Div as Ajax.ActionLink

前提是你 提交于 2019-12-10 21:11:35

问题


Is it possible to create Ajax.ActionLink which has instead of text, the whole DIV?

I'd like to map div on Ajax.ActionLink


回答1:


I don't think that this will work using the standard MVC Ajax scripts. I believe that the MVC javascript is created to use an <a> element by default. On a different note, embedding a div tag within an <a> is not valid XHTML. What are you trying to achieve?

Using Jquery is probably the easiet way you want to go. As an example:

<div onclick="SomeAjaxFunction()">some div content</div>

function SomeAjaxFunction()
{
  $.get('<%= Url.Action("SomeAction", "InSomeController") %>', function(data) {
      $('.result').html(data); // assuming a partial view
      alert('Load was performed.');
});
}

However, if you are dead set on using MS Ajax, to work with divs, you need to possibly look at the Sys.Mvc.MvcHelpers._asyncRequest function and do some of your own re-wrapping to make it usable. I have not tried or tested this, so use at your own risk. (Stick with the Jquery, there is far better help and support available.)



来源:https://stackoverflow.com/questions/3307451/div-as-ajax-actionlink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!