Showing posts with label MVC. Show all posts
Showing posts with label MVC. Show all posts

Thursday, April 26, 2012

"Add Deployable Dependencies" option in Visual Studio 2010 When you want to deploy ASP.NET MVC application

0 comments

I would like to share this option for the developer who are using Visual studio 2010 for development and working on ASP.NET MVC application. When you try to host your application (ASP.NET MVC) on window server and if you server haven't installed MVC then you might be get following type of error.

Could not load file or assembly 'System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified

Friday, March 30, 2012

Microsoft announced ASP.NET MVC,web API and Razor as Open Source

0 comments
I have read today scottgu's blog entry about announcement of release the source code of ASP.NET MVC, Web API, and Razor under an open source license (Apache 2.0).
Now you can download source code from codeplex and if you want contribute in that then you can do it there.
Hope that making it open source will improve ASP.NET MVC, Web API, and Razor to better level because now it is open to every people. (Power of Open Source!)

Read more about this

Saturday, March 3, 2012

ASP.NET Web API - Great collection of learning resources

0 comments
ASP.NET team launched MVC4 Beta with new asp.net web API template and all .net peoples looking for good resources to learn more about that and build application on that.

I was also searching for that and found good links here with all tutorials, videos and samples.

Tugberk Ugurlu lists a bunch of great resources for getting started with ASP.NET Web API in his blog post, follow below link.


Thursday, March 1, 2012

Extend the built-in ASP.NET DataAnnotations using DataAnnotations Extensions

0 comments
If you have worked with development of web service, silverlight application or mvc applicaiton then you know about DataAnnotations class to validate DTO client side as well as server side.

DataAnnotations contains mostly Required, Range, RegularExpression and StringLength and to see full list of attributes it contains visit this msdn link "Using Data Annotations to Customize Data Classes" .

In my mvc application there is person class (Model) and validation for email as per below (by regular expression)



Scott Kirkland has extended this and created excellent DataAnnotations Extensions pacakge for .net to allow more validation attributes, also he has explained about this in his blog post with examples.

so after installing DataAnnotations Extensions Nuget package i can write email validation as per below





Following are list of more validation attributes available in  DataAnnotations Extensions
  •     CreditCardAttribute
  •     CuitAttribute
  •     DateAttribute
  •     DigitsAttribute
  •     EmailAttribute
  •     EqualToAttribute
  •     FileExtensionsAttribute
  •     IntegerAttribute
  •     MaxAttribute
  •     MinAttribute
  •     NumericAttribute
  •     UrlAttribute
  •     YearAttribute
You can see demo of each & every attributes here.

Wednesday, February 22, 2012

Bundling and Minification in ASP.NET 4.5 and MVC4

0 comments
In MVC4 Beta release from Microsoft last week, have a look with series of blog and would like to talk about one feature called Bundling and Minification which is also available to ASP.NET 4.5

Bundling:
As per name suggest it bundle or combine multiple javascript, css requests to fewer Http request means bundle by type of file
Minifying: will remove white space form css and javascript which cause to reduce download size of that files

Let's if we have project with 3 javascript and 3 css files




Bundling and minifying the .css files
If you want to add css file as per listed above in fig then  you need to add refernce of all 3 files as per below which will result in to 3 separate http requests but this feature allow you to bundle and minify in to styles folder and call it in only one http request as per below.


Same way it will apply to javascript files as well
This is simple overview of this feature you can read about it in more details on scottgu's blog.

Tuesday, February 21, 2012

Add Elamh to ASP.NET MVC application

0 comments
Elmah is great open source module developed by Atif Aziz to handle error logging for asp.net application and there is nuget pacakge also available to add in to existing application. If you are new to Elmah then visit my previous post to started with it.

Alexander Beletsky has developed Elmah.Mvc for asp.net mvc application it is also available through Nuget package.
You can add it by GUI tool as per below
Go to Reference> Manage Nuget Pacakge > Search Elamh.MVC


OR By Package Manager console as per below

Now Hit admin/elmah with your app's URL,you will get elmah page. That's it!

Please refer Author's blog post about what are the changes in this MVC version of Elmah.



Monday, February 20, 2012

Paging sorting with WebGrid in MVC3 and razor

0 comments
If you have worked with MVC3 and Razor view engine then you may be aware that when will you create new view for details on bases of IEnumerable Model then it
it will create cshtml code with foreach loop which will cause to render data in Grid Format as per shown in below fig.


Now if you want Paging and sorting to this data then manually you need to make lots of efforts to achieve desired result.
But Microsoft has already built very good helpers called WebGrid, to achieve this so you do not need to do that manually.
So it will look like as per below after replacing above code.


If you notice URL in above fig then you can see that it WebGrid will automatically make sorting request with proper parameter you can also change parameter
name to customize URL,e.g.
var grid = new WebGrid(Model, canSort: true, canPage: true, rowsPerPage: 2,sortFieldName:"S", sortDirectionFieldName:"SD");

You can apply style to particular column by style: attribute. http://stackoverflow.com/questions/9357786/apply-specific-width-in-column-of-webgrid-in-mvc3


Look at



Saturday, February 18, 2012

Look at ASP.NET MVC4 Beta!

0 comments
Microsoft has released ASP.NET MVC4 Beta officially and Jon Galloway announced regarding of it in his blog with introduction to ASP.NET web API.

Top Most Features
  •     ASP.NET Web API
  •     Refreshed and modernized default project templates
  •     New mobile project template
  •     Many new features to support mobile apps
  •     Recipes to customize code generation
  •     Enhanced support for asynchronous methods
Also you can build ASP.NET MVC project with Nuget Package
For more details and installation tips look at http://www.asp.net/mvc/mvc4



Saturday, January 14, 2012

Paypal integration in MVC3 and Razor

16 comments
Today i would like to describe here step by step procedure to integrating paypal integration (express checkout) in MVC3 web application using razor view engine.

1)Create new MVC3 internet web application.

2)change Index page under Home section and as per below fig





3) Create paypal model class



4) Create action in home controller to post data to paypal



here we post item information in form so we can retrieve it using parameter as you can see that value when you debug as per below


in that you need to set following parameters in web.config
  • BusinessAccountKey: business account key for seller
  • UseSandbox: weathere to use sanbox or live
  • CancelURL: return to this when user cancel
  • ReturnURL: return after payment
  • NotifyURL: use for IPN to notify
  • CurrencyCode: transcation in which currency 
to use sandbox you need to create account at https://developer.paypal.com/
and in that you can create business account as well as buyers account to testing as per shown in fig



I have added that in web.config as per below



If you new for paypal integration then first go through this introduction here .

5)create view of this action (empty view) and code as per below



6) Now run the site and click pay with paypal , you will be redirecting to paypal as per below


here you can pay with your personal test account and redirect to back as per app-setting URLs

7) To handle redirected request you need to create following controller and respective views with your logic and message.
  • RedirectFromPaypal 
  • CancelFromPaypal 
  • NotifyFromPaypal