ASP. net mvc displays exception information, asp. netmvc displays

Source: Internet
Author: User

ASP. net mvc displays exception information, asp. netmvc displays

More ASP. NET development, and its exception information display is also used. But in ASP. net mvc, it is another situation.

I used to use Internet Explorer only. Now I am developing ASP. net mvc program, in order to capture the exception information, Firefox firebug plug-in is also used up, it actually can help us a lot, can refer to the "Internal Server Error" http://www.cnblogs.com/insus/p/3418942.html.

The following is an ultra-simple calculator that implements addition, subtraction, multiplication, and division. If you have input exception data, we can capture the exception information.


Create a view Action and a computing operation in the control.



Complete the jQuery Code as follows:


Reference jQuery, jQueryUI, and UI styles.

See the results:

 


How does Aspnet Mvc display an error message in the Controller?

You can create a method with a returned value and call this method when prompted. The returned value of this method is the prompt you want.

That's the first floor! You can also include parameters to make it more flexible!
Public string XxxController (Object obj ){
Return "<script> alert ('" + obj. ToString () + "') </script> ";
}

How to handle mvc information prompts

In addition, it seems that you have not understood what a layer-3 architecture is. The so-called MVC. M is a Model, V is a View, and C is a Control.
My code is ASP. net mvc three-layer architecture

Models is only the entity printing of the database. There should be no logic, and database operations should not be performed.
The logic should be written in the logic layer, and the interface jump judgment should be in the interface layer. Below is a small example of mine.

Take a verification login as an Example
The interface layer is generally called UIL.
Protected void button#click (object sender, EventArgs e)
{
List <User> Users = BLL. GetUserInfo (txtUserName. Text, txtPassword. Text );

If (Users. Length> 0)
{
Response. Write ("Login successful ");
}
Else
{
Response. Write ("Logon Failed ");
}
}

The following is the logic layer code. The business logic layer is generally called BLL.
Public static List <User> GetUserInfo (string user, string password)
{
String newPassword = GetMD5Hash (password); // The password is encrypted here. The database stores the MD5-encrypted password, and the business logic layer generally processes complicated logic. for example, encryption logic
List <User> Users = DAL. GetUserInfo (user, newPassword );

Return Users;
}

The following is the data access layer code. The data access layer is generally called DAL.
Public static List <User> GetUserInfo (string user, string password)
{
List <User> Users = new List <User> ();
String SQL = "select * from User where Password = '" + password + "' and User = '" + user + "'"; // put the Password before writing the where clause. because the Password is encrypted, it can prevent SQL injection attacks.
SqlDataAdapter da = new SqlDataAdapter (SQL, "database connection string ");
DataSet ds = new DataSet ();
Da. Fill (ds );

For (int I = 0; I <ds. Tables [0]. Rows. Count; I ++)
{
User user = new User (ds. tables [0]. rows [I] ["ID"]. toString (), ds. tables [0]. rows [I] ["User"]. toString (), ds. tables [0]. rows [I] ["Password"]. toString ());
Users. Add (user );
}

Return Users;
}

There will also be a Model layer called the template layer. It is the printing of the data table structure. The Model layer is a shared layer, and the other three layers will be used.
For example, there is a full text in the database...>
 

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.