Learn MVC application development, changed the insus.net before the development of ASP, the previous development is the server side, and now use jquery Ajax in the implementation. Think of and consider a lot of problems, also encountered a lot of problems, some solved, some still stay, hope to solve them all.
As this problem, "Internal Server Error" http://www.cnblogs.com/insus/p/3418942.html let insus.net impressive, solve it himself, spent insus.net a lot of time.
Today's blog post, Insus.net is to share a better solution, the exception of the server or in the memory of the custom exception, can be displayed in jquery Ajax.
Come back and look here. "MVC member registration" http://www.cnblogs.com/insus/p/3439599.html in the stored procedure [dbo]. [Usp_member_register] will see the custom exception information to determine whether the account has been registered:
IF EXISTS (SELECT TOP 1 1 from [dbo].[ Member] WHERE [Account] = @Account) BEGIN RAISERROR (N ' This username [%s] has already been registered, please change and re-register. ', 16,1, @Account) returnend
Ok, we'll need this custom exception information to throw to jquery later.
Open the Practice project, find the previous JS class library "Create your own Common JS library" http://www.cnblogs.com/insus/p/3427673.html add two extension methods:
Then, open the view view that you want to reference this JS library, such as member/register.cshtml:
Then modify the jquery code to Comment out:
alert (Errorthrown);
Add an arrow sentence:
In the following live demo, Insus.net has tried to measure a user who has already been registered, and it has custom exception information that normally displays the stored procedure. It also tests that the stored procedure is deleted, and it can also hint that the stored procedure cannot be found. Finally insus.net which stored procedure to re-build, it can be used normally.