Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 如何在同一视图中为基础ViewModel和派生ViewModel使用两个不同的EditorTemplate?_Asp.net Mvc_Asp.net Mvc 3_Asp.net Mvc 2 - Fatal编程技术网

Asp.net mvc 如何在同一视图中为基础ViewModel和派生ViewModel使用两个不同的EditorTemplate?

Asp.net mvc 如何在同一视图中为基础ViewModel和派生ViewModel使用两个不同的EditorTemplate?,asp.net-mvc,asp.net-mvc-3,asp.net-mvc-2,Asp.net Mvc,Asp.net Mvc 3,Asp.net Mvc 2,我有很多从基础ViewModel派生的ViewModel 是否可以在同一视图中显示来自基础ViewModel的衍生ViewModel部分的EditorTemplate,以及衍生零件的不同模板?如果是,如何完成 基本视图模型: public class ShowQuestionViewModel { public int Question_ID { get; set; } public String Question_Wording { get; set;

我有很多从基础ViewModel派生的ViewModel

是否可以在同一视图中显示来自基础ViewModel的衍生ViewModel部分的EditorTemplate,以及衍生零件的不同模板?如果是,如何完成

基本视图模型:

public class ShowQuestionViewModel
    {
        public int Question_ID { get; set; }
        public String Question_Wording { get; set; }
        public String Question_Type { get; set; }
        public String Question_Number { get; set; }
        public Boolean Visible { get; set; }
        public Boolean IsAnswered { get; set; }

    }
public class ShowMatrixQuestionViewModel : ShowQuestionViewModel
    {
        public Dictionary<MatrixRows, List<MatrixColumns>> columnrow;
        public List<MatrixColumns> columns;
        public List<MatrixRows> rows;

        public ShowMatrixQuestionViewModel()
        {
            columns = new List<MatrixColumns>();
            rows = new List<MatrixRows>();
            columnrow = new Dictionary<MatrixRows, List<MatrixColumns>>();
        }
    }

    public class MatrixColumns
    {
        public int Column_ID { get; set; }
        public int Column_Number { get; set; }
        public String Column_Description { get; set; }
        public Boolean IsAnswer { get; set; }
    }

    public class MatrixRows
    {
        public int Row_Id { get; set; }
        public String Row_Number { get; set; }
        public String Row_Description { get; set; }
    }
派生视图模型:

public class ShowQuestionViewModel
    {
        public int Question_ID { get; set; }
        public String Question_Wording { get; set; }
        public String Question_Type { get; set; }
        public String Question_Number { get; set; }
        public Boolean Visible { get; set; }
        public Boolean IsAnswered { get; set; }

    }
public class ShowMatrixQuestionViewModel : ShowQuestionViewModel
    {
        public Dictionary<MatrixRows, List<MatrixColumns>> columnrow;
        public List<MatrixColumns> columns;
        public List<MatrixRows> rows;

        public ShowMatrixQuestionViewModel()
        {
            columns = new List<MatrixColumns>();
            rows = new List<MatrixRows>();
            columnrow = new Dictionary<MatrixRows, List<MatrixColumns>>();
        }
    }

    public class MatrixColumns
    {
        public int Column_ID { get; set; }
        public int Column_Number { get; set; }
        public String Column_Description { get; set; }
        public Boolean IsAnswer { get; set; }
    }

    public class MatrixRows
    {
        public int Row_Id { get; set; }
        public String Row_Number { get; set; }
        public String Row_Description { get; set; }
    }
公共类ShowMatrixQuestionViewModel:ShowQuestionViewModel
{
公共词典专栏行;
公共列表列;
公共列表行;
公共ShowMatrixQuestionViewModel()
{
columns=新列表();
行=新列表();
columnrow=新字典();
}
}
公共类矩阵列
{
公共int列_ID{get;set;}
公共int列_编号{get;set;}
公共字符串列_说明{get;set;}
公共布尔值IsAnswer{get;set;}
}
公共类矩阵行
{
public int Row_Id{get;set;}
公共字符串行数{get;set;}
公共字符串行描述{get;set;}
}

因此,当我使用EditorFor(x=>ShowMatrixQuestionViewModel)时,我想对来自ShowQuestionViewModel的属性使用一个特殊的编辑器。

您可以创建一个单独的编辑器模板:

@model ShowMatrixQuestionViewModel
@Html.EditorForModel()

然后定义一个自定义编辑器模板
~/Views/Shared/EditorTemplates/showmarixquestionviewmodel.cshtml
,您可以在其中自定义所有属性,包括基本类型的属性。

只需为
showmarixquestionviewmodel
创建一个自定义编辑器模板。但是,当您这样做吗?