I am a Java developer, new to .NET. I am working on a .NET MVC2 project where I want to have a partial view to wrap a widget. Each JavaScript widget object has a JSON data object that would be populated by the model data. Then methods to update this data are bound to events when data is changed in the widget or if that data is changed in another widget.
代码是这样的:
MyController
:
virtual public ActionResult DisplaySomeWidget(int id) {
SomeModelView returnData = someDataMapper.getbyid(1);
return View(myview, returnData);
}
myview.ascx
:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SomeModelView>" %>
<script type="text/javascript">
//creates base widget object;
var thisWidgetName = new Widget();
thisWidgetName.updateTable = function() {
// UpdatesData
};
$(document).ready(function () {
thisWidgetName.data = <% converttoJSON(model) %>
$(document).bind('DATA_CHANGED', thisWidgetName.updateTable());
});
</script>
<div><%:model.name%></div>
我不知道的是如何将数据发送到SomeModelView
多个位置,然后能够使用这些数据填充小部件,并将其转换为JSON.我在控制器中看到了一些真正简单的方法,但在视图中没有看到.我想这是一个基本的问题,但我已经花了几个小时试图把这个问题弄清楚.