Debasis Mohapatra

Debasis Mohapatra

  • 1.6k
  • 376
  • 19.2k

How to do model field validation in c# MVC

Jan 15 2019 12:08 AM
Please find the below model code. I want to do field validation. why the viewbag.msg doesn't show the error that [Required(ErrorMessage = "User is required for mobile model details")]
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace SudentRegistration_MVC_Project.Models
public class Mobile
public int id { get; set; }
public string Mobile_brand { get; set; }
[Required(ErrorMessage = "User is required for mobile model details")]
public string mobile_model { get; set;}
public int mobile_price { get; set; }
public string mobile_description { get; set; }
public List MobileList { get; set; }

Brought to you by:

Answers (3)