如何:处理MVC剃刀列表中的复杂对象 [英] how to: deal with complex objects mvc razor lists

查看:70
本文介绍了如何:处理MVC剃刀列表中的复杂对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从事开发人员已经很多年了,其中不包括Web前端

因此,我决定解决我想知道"列表中的一项.这次是mvc3

我试图为此对象创建一个简单的对象,但被卡在"MyItems"列表中.
我正在寻找要使用MyClass属性+(添加MyItems的订单项)的一项操作来创建/编辑的创建/编辑.

到目前为止,我已经尝试创建一个局部视图,该局部视图使用jquery克隆节点以为MyItems创建单个项目,并将该局部视图包括在我的Create视图中.但是,当我提交保存时,我的对象绑定没有正确,MyItems始终为空.

关于此事的任何指针和指向教程等的链接都很大
感激的

也欢迎提供建议和解决方案

I have been a developer for many years non of which have been on web front end

So i decieded to tackle one of the items on my "wanna know" list. this time it''s mvc3

i am attempting to create simple crud for this objet( below ) but am stuck on the "MyItems" list.
I am looking for the create / edit to be created with one operation for both the MyClass properties + ( adding the line items for MyItems ).

so far i''ve attemnpted to create a partial view which uses jquery to clone nodes to create a single item for MyItems and include that partial view in my Create view. however i am not getting the objet binding correct for when i submit the save, MyItems is always empty.

Any pointers and links to tutorials etc on the matter are greatly
appreciated

Advice and solutions welcome as well

public class MyClass
{
    public MyClass()
    {
        MyItems = new List<MyItem>();
    }

    [Required]
    public string Name { get; set; }
    public int Age { get; set; }

    public List<MyItem> MyItems { get; set; }

    public class MyItem
    {
        public string Lable { get; set; }
        public string Value { get; set; }
    }
}

推荐答案

这是您的ViewModel吗?使用MVC3进行此操作最简单的方法是使用@ Html.XXXFor方法创建适当的控件以显示您的数据,然后它将在回发时填充它们.我更喜欢使用AJAX和JSON,在这种情况下,您可以使用javascript构建对象,但是如果您乐于进行回发,请让框架为您完成.请说明"myclass"如何进入您的视图以及您的视图如何处理它,我很乐意回答更多.
Is this your ViewModel ? The easiest way to do this with MVC3, is to use the @Html.XXXFor methods to create appropriate controls to show your data, and then it will populate them on postback. I prefer to use AJAX and JSON, in which case you build your objects in javascript, but if you are happy to do postbacks, let the framework do it for you. Please explain how ''myclass'' gets in to your view and how your view deals with it, and I''ll be happy to answer more.


这篇关于如何:处理MVC剃刀列表中的复杂对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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