是有可能的局部视图在MVC Asp.net渲染后揭开序幕javascript函数? [英] Is it possible to kick off a javascript function after a partial view renders in MVC Asp.net?

查看:79
本文介绍了是有可能的局部视图在MVC Asp.net渲染后揭开序幕javascript函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我preface这个问题的事实,我是很新的MVC。

Let me preface this question with the fact that I am very new to MVC.

我在哪里,我在一个局部视图渲染devex preSS电网的实例。

I have an instance where I am rendering a devexpress grid in a partial view.

@Html.Partial("MyGridPartial", Model)

我需要,该模型已经通过这个局部视图渲染填充的时刻揭开序幕JavaScript函数。我试图通过这个来做到这一点。

I need to kick off a javascript function at the moment that the model has been populated via this partial view render. I attempted to do this via this. :

settings.ClientSideEvents.EndCallback

我能到这一点,但当时我没有模型本身填充所以并没有好处。我不知道是否有人意识到踢的通用方法/连接到局部视图渲染,以跳入一些客户方的javascript code。

I can get to this point, but at that time I do not have the model itself populated so it does no good. I was wondering if anyone is aware of a generic way of kicking/attaching to a partial view render in order to jump into some clientside javascript code.

推荐答案

如果您在此渲染部分作为视图的正常流动的一部分被呈现,答案是否定的。

If you are rendering this partial as part of the normal flow of a View being rendered, the answer is NO.

由于这个原因是部分被转换成字符串之前父视图甚至呈现。在这一点上,没有你的标记已被视为由浏览器,没有JScript的已经读出

Reason for this is the Partial is converted into a string before the parent View is even rendered. At that point, none of your markup has been seen by the browser, no jscript has been read.

如果,在另一方面,则呈现的部分在JQuery的准备功能:

If, on the other hand, you rendered the partial in your JQuery Ready function:

$(文件)。就绪(函数(){

我想你需要使用一个动作部分(部分即得到由操作方法调用)。行动局部模板可以将您的JQuery就绪函数中通过引用网址被调用(REST风格):

I think you would need to use an Action Partial (Partial that gets called by an action method). Action Partials can be called within your JQuery Ready function by referencing the url (restfully):

$('#divMyGridPartial').load('/Grids/MyGridPartial/{id}');

和任何跟进的JScript / jQuery的功能,可以准备系列中被调用。

and any follow up jscript/jquery functions can be called within the ready series.

部分动作的另一个优点,该模型是操作方法中形成的,并且可以上下文创建你所需要的(理想铰断传递的ID)。

The other advantage of an Action Partial, the Model is formed within the action method and can be created contextually to what you need (ideally hinging off an id passed).

这篇关于是有可能的局部视图在MVC Asp.net渲染后揭开序幕javascript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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