Posts

Showing posts with the label MVC

Simply Notes #3: Multiple File Upload in ASP.Net MVC

Image
Here is requirement I tripped into "Give me an option to upload multiple images which blah blah blah". Blah blah part is where it says do not use the easy way like input type multiple . Below is the POCO  for this sample which is the View Model Checkout the UIHint attribute which will let us use DisplayFor or EditorFor in any of the views To make this control reusable create a template File.cshtml which is type bound to custom Image type The jQuery script will copy the input type file element and appends to the last file element whenever a file is selected to upload on the input element. The Action here is to ModelBind image array to the action parameter The Bind  attribute takes care of the naming convention that takes behind the scenes when rendering the element. If you are using the template to render any element the framework will append the model property names of the nested elements. In this example it will render input element with name="PIma

Cascading Dropdownlist in MVC3- the ajax way

Image
Creating a dropdownlist the ajax way using jQuery is kind of messy. Ajax Helpers in MVC3 has an elegant alternative using unobtrusive jquery. Lets first create a simple page with ajax form The  UpdateTargetId  property of the AjaxOptions says where the partial view is to be inserted on form submit. The corresponding controller will be Create a partial view that will hold the second dropdownlist like this Now one last important thing do not forget to include the unobtrusive script in your layout page In this example when we have binded the on change of event so that the form it is contained in is posted. The argument name of the method SelectFromDDL1  and the id of dropdownlist should be the same so that it is posted when the form is submitted. Using the same  you can create any number of cascading dropdownlists. 

KISS Tabular View

Image
KISS- Keep it Simple Stupid This post is about a simple html tabular view using bootstrap  and a kind of raw grid with sort & search option using ASP.MVC framework. I always like to keep a lot of things (not everything) simple, not that i don't like owning NOT so simple things ;)  From development perspective the KISS principle has been spreading lately. Simplicity, the first thing that pops up when i hear that word, it would be Google . Well in fact "simple" is more like "beauty" it's in the eye of the beholder. Here is a sample whose idea on simple contradict with that of mine. May be we can't jump into conclusion that if something is simple to someone it is the same for the other. So on that same idea of Simple i will try to make a simple page with a simple grid with simple lines of code. Here is simple table which has got nothing to do with this post. Let us Create trivial class Employee like this Now lets create a PersonContro

Code First!!!

Image
Code first- I just love this approach, well any developer would. MVC has been haunting since long ago. So thinking to my self better late than never gave it shot and found it to be pretty neat & interesting. And Microsoft as before with MVC, Entity framework, etc etc leaves you wondering how they did that!!! . Lets start coding (if we get a chance to ;) ), Select ASP.NET MVC3 Web Application in the next select Internet application and try razor view engine with html5 Now check your solution explorer you will see quite a lot of things that has come from thin air. Don't b shocked there is still to come Microsoft now needs a developer who knows to create a class For this sample project let me create following two classes Employee and Department and add to Models folder      public   class   Employee     {          public   int  Id {  get ;  set ; }          public   string  Name {  get ;  set ; }          public   string