Asp.net在一个视图MVC多模型(创建,更新) [英] Asp.net with MVC multiple model in one view (create, update)

查看:159
本文介绍了Asp.net在一个视图MVC多模型(创建,更新)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对创建和更新多个模型asp.ne问题的mvc在一个视图中
我是在考试系统工作
类问题和答案类
问题是aparent类和解答是子类

I have problem in asp.ne Mvc with multiple model in one view on create and update I 'm work on exams system class Questions and class Answers Question is aparent class and Answers is a child class

[Bind(exclude("id"))]

class Quesions
{
public string question{get; set;}
public Datetime Timepostquestion{get; set;}
}
[Bind(exclude("id"))]
class Answers
{
public string answer{get; set;}
public Datetime Timepostanswer{get; set;}
public questionId {get; set;}
}

在视图中我用两个类如何在插入和更新使用类
有什么办法,我要解决我的问题。

in a view I use two classes how to use classes in insert and update what a way which I have to solve my problem

推荐答案

您应该换另一个对象的两个对象的视图,通常被称为一个视图模型

You should wrap the two objects in another object for the View, commonly referred to as a "ViewModel".

public class QuestionAnswerViewModel
{
   public Question Question { get; set; }
   public ICollection<Answer> Answers { get; set; }
}

绑定到您的视图。

Bind to that in your View.

然后使用类似的 AutoMapper 将其映射回你的两个实体。

Then use something like AutoMapper to map it back to your two entities.

这篇关于Asp.net在一个视图MVC多模型(创建,更新)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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