ASP. NET MVC3 Usage Phase Summary

Source: Internet
Author: User
Some time ago, I participated in a small project in the company. The access to ASP. net mvc is not long and ASP. NET MVC1 is used before. However, ASP. NET MVC3 is used as required. I simply searched for some information on the Internet, and I usually learned one by one. After a period of exploration, I was a little familiar with it. Here we will record some problems encountered during the learning and usage process and Mark them. I. Razor view engine many articles have been specially introduced on this web page, which is very detailed. If you need it, you can search by baidu/Google! Personally, I feel better about the following:

 

  • Clear and simple syntax
  • Visual Studio provides smart prompts and syntax coloring for Razor.
  • @ *** Annotation syntax
  • The Html. Raw method provides output without HTML encoding.
  • Supports code sharing among multiple views (_ viewstart. cshtml)

 

This is especially true for those who have worked in ASP. NET MVC1 !!

 

2. Model verification the Model verification. If you don't need to talk about it, paste the Code directly. I believe you will find the advantage 1 [PropertiesMustMatch ("NewPassword ", "ConfirmPassword", ErrorMessage = "the new password does not match the Confirmed password. ")]
2 public class ChangePasswordModel
3 {
4 [DisplayName ("no.")]
5 public string StoreID {get; set ;}
6
7 [DisplayName ("current password")]
8 [Required (ErrorMessage = "Enter the current password")]
9 public string OldPassword {get; set ;}
10
11 [Required (ErrorMessage = "enter a new password")]
12 [DataType (DataType. Password)]
13 [ValidatePasswordLength]
14 public string NewPassword {get; set ;}
15
16 [Required (ErrorMessage = "enter the password")]
17 [ValidatePasswordLength]
18 [DataType (DataType. Password)]
19 public string ConfirmPassword {get; set ;}
20
21 [DisplayName ("current password 2")]
22 [Required (ErrorMessage = "Enter the current password 2")]
23 public string OldPassword2 {get; set ;}
24
25 [Required (ErrorMessage = "Enter new password 2")]
26 [DataType (DataType. Password)]
27 [ValidatePasswordLength]
28 public string NewPassword2 {get; set ;}
29
30 [Required (ErrorMessage = "enter the password for confirmation 2")]
31 [ValidatePasswordLength]
32 [DataType (DataType. Password)]
33 public string ConfirmPassword2 {get; set ;}
34} 3. Note that ajax is a Controller Action method. JsonResult1 public JsonResult IsExist (string Name) is returned)
2 {
3 JsonResult supjs = new JsonResult
4 {
5 Data = myService. CheckStoreName (Name ),
6 };
7 return Json (supjs, JsonRequestBehavior. AllowGet );
8} When MVC1 is used, View can be used directly, such as 1 $. getJSON ('/Ajax/IsExist/', {Name: Name },
2 function (json ){
3 result = json;
4 });
5 if (result = true ){
6 alert ("the one you added already exists, please add again ");
7 document. getElementById ("Name"). focus ();
8 return false;
9} But when using MVC3 and View, it needs to be changed to result. Data instead of using result directly.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.