【问题标题】:ASP MVC to Silverlight MVVM issuesASP MVC 到 Silverlight MVVM 问题
【发布时间】:2009-11-12 23:13:10
【问题描述】:

我正在将一个 asp.net MVC 应用程序转换为 silverlight,由于我在我的 mvc 应用程序中做了一些“非标准”的事情,我很难弄清楚如何在其中实现它Silverlight MVVM。

基本上,我是从元数据生成所有视图,包括链接、按钮等。其中一个我无法理解如何在 Silverlight 中执行的示例是,我将一个动作集合传递给了我的视图,并且有一个 html 帮助类,然后将这些操作转换为链接

        public static string GenericLinks(this HtmlHelper htmlHelper, int location, bool inTable, int? parentRecordId, List<ModelAction> 

actions)
        {
            int actionNo = 1;
            StringBuilder text = new StringBuilder();
            foreach (var action in actions)
            {
                if (action.LocationType == location)
                {
                    if (inTable)
                        text.Append("<td>");
                    else
                        if (actionNo > 1)
                            text.Append(" | ");
                    text.Append(htmlHelper.ActionLink(action.Label, action.ActionTypeLookup.CodeName, new { actionId = action.ModelActionId, 

parentRecordId = parentRecordId }));
                    if (inTable)
                        text.Append("</td>");
                    actionNo++;
                }
            }
            return text.ToString();
        }

这在 MVC 中确实很有效。

MVVM 中的等价物是什么? 我希望我可以做一些更优雅的事情,更多的是在我的视图模型中创建我的动作,并以某种方式绑定到我视图中的这些动作......

【问题讨论】:

    标签: silverlight mvvm


    【解决方案1】:

    对于类似的事情,您可能需要创建一个自定义控件。然后你可以把它放在你的视图中,并将它绑定到你的 ViewModel 中存在的 Actions 集合中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多