相关疑难解决方法(0)

什么是MVC中的ViewModel?

我是ASP.NET MVC的新手.我在理解ViewModel的目的时遇到了问题.

什么是ViewModel,为什么我们需要一个用于ASP.NET MVC应用程序的ViewModel?

如果我能有一个简单的例子,那就更好了.

asp.net-mvc viewmodel

411
推荐指数
9
解决办法
30万
查看次数

将数据注释添加到由实体框架生成的类

我有实体框架生成的以下类:

public partial class ItemRequest
{
    public int RequestId { get; set; }
    //...
Run Code Online (Sandbox Code Playgroud)

我想把它变成一个必填字段

[Required]
public int RequestId { get;set; }
Run Code Online (Sandbox Code Playgroud)

但是,因为这是生成的代码,这将被消灭.我无法想象一种创建分部类的方法,因为属性是由生成的分部类定义的.如何以安全的方式定义约束?

c# entity-framework asp.net-mvc-4

92
推荐指数
4
解决办法
6万
查看次数

使用Entity Framework 5.0进行数据注释(数据库优先)

如果我使用Entity Framework(v5.0)数据库第一种方法,那么使用数据注释进行验证的最佳方法是什么?

这是我的Entity Framework创建的部分类:

//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System.ComponentModel.DataAnnotations;

namespace ACore
{
    using System;
    using System.Collections.Generic;

    public partial class PayrollMarkup_State
    {
        [UIHint("StatesEditor")] // <-- I added this line but it will be overwritten
        public string State { get; set; }
        public …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework data-annotations entity-framework-5

22
推荐指数
1
解决办法
2万
查看次数