background preloader

MVC

Facebook Twitter

ASP.NET MVC Improving Productivity with the WebGrid. Practical .NET ASP.NET MVC: Improving Productivity with the WebGrid The WebGrid will certainly make the developers who use it more productive.

ASP.NET MVC Improving Productivity with the WebGrid

ASP.NET MVC & jQuery UI autocomplete - Stuart Leeks. UPDATE: I've written a follow-up post that shows how to achieve this using Html.EditorFor here.

ASP.NET MVC & jQuery UI autocomplete - Stuart Leeks

If you get me started talking about ASP.NET MVC then it is quite possible that I’ll end up talking about Progressive Enhancement or Unobtrusive JavaScript. Aside from the usability and performance benefits that these techniques can bring, I find that they also help me to write JavaScript in a more modular, more reusable way than if I hack some script into a page. ASP.NET MVC & jQuery UI autocomplete Part 2 (EditorFor) - UK Premier Support for Developers.

ASP.NET MVC: Supplying HTML attributes with EditorFor - Stuart Leeks. My colleague Simon Ince and I recently discovered that we had been working on the same problem independently so we combined our efforts and have written a joint blog post on our team blog.

ASP.NET MVC: Supplying HTML attributes with EditorFor - Stuart Leeks

The problem was something that I’d encountered in a number of blog posts that used modified editor templates (jQuery UI datepicker, aria-required and autocomplete). In each of these posts I ended up adding a custom template, and then updating it to output an attribute in the rendered HTML. The thing that bothered me about all of these posts is that they didn’t compose well. For example, if you wanted to combine autocomplete and aria-required then you’d have to merge the changes to the templates.

In the blog post, Simon and I walk through a fairly simple way to solve this problem with the introduction of HtmlAttributeProvider. aria-required In the remainder of this post I thought I’d show how the previous solutions would look with the new HtmlAttributeProvider. jQuery UI datepicker. ASP.NET MVC: Adding Html attributes in Templated Helpers (EditorFor) - UK Premier Support for Developers. ASP.NET MVC: Supplying HTML attributes with EditorFor - UK Premier Support for Developers. Injecting Custom HTML Attributes in ASP.NET MVC - UK Premier Support for Developers.

Modelbinding with complex objects in ASP.NET MVC. Basics: The modelbinding in ASP.NET is “relatively” clever and you are able to bond almost everything.

Modelbinding with complex objects in ASP.NET MVC

All you have to do is to understand how the binding works and you often found that out if you take a look via Fiddler and co. at what is transmitted as HTTP. Object model public class Foobar { public string Buzz { get; set; } public int Foo { get; set; } public List<Foobar> Children { get; set; } } The model is very simple but it contains objects from the same type as a list. Action method We want to transmit those files to the computer (who doesn’t interact with them at all but it’s enough for the example): public ActionResult Test(string name, List<Foobar> foobars) { return View("Index"); } I present you three different models of how to integrate complex objects into this method.

Model 1: easy form (Postback – no AJAX) With the “[NUMBER]” of the field the MVC Binder will know that this is only a list. Model 2: send the form via jQuery with Ajax. Model Binding To A List. Download the sample project to play with the code as you read this blog post.

Model Binding To A List

Using the DefaultModelBinder in ASP.NET MVC, you can bind submitted form values to arguments of an action method. But what if that argument is a collection? Can you bind a posted form to an ICollection<T>? Sure thing! It’s really easy if you’re posting a bunch of primitive types. Public ActionResult UpdateInts(ICollection<int> ints) { return View(ints);} You can bind to that by simply submitting a bunch of form fields each having the same name. If you were to take fiddler and look at what data actually gets posted when clicking the submit button, you’d see the following. ints=1&ints=4&ints=2&ints=8 The default model binder sees all these name/value pairs with the same name and converts that to a collection with the key ints, which is then matched up with the ints parameter to your action method.

Nadeem Afana's blog · ASP.NET MVC 5 Internationalization. Public static class CultureHelper private static readonly List<string> _cultures = new List<string> { "en-US",

Nadeem Afana's blog · ASP.NET MVC 5 Internationalization

What’s the Difference Between a Value Provider and Model Binder? ASP.NET MVC 3 introduced the ability to bind an incoming JSON request to an action method parameter, which is something I wrote about before.

What’s the Difference Between a Value Provider and Model Binder?

For example, suppose you have the following class defined (keeping it really simple here): public class ComicBook { public string Title { get; set; } public int IssueNumber { get; set; }} And you have an action method that accepts an instance of ComicBook: [HttpPost]public ActionResult Update(ComicBook comicBook) { // Do something with ComicBook and return an action result} Meleze-Meleze.Web. Sending JSON to an ASP.NET MVC Action Method Argument. UPDATE: The JsonValueProviderFactory is now registered by default in ASP.NET MVC 3.

Sending JSON to an ASP.NET MVC Action Method Argument

So if you’re using ASP.NET MVC 3, you can ignore that part of this blog post. Javier “G Money” Lozano, one of the good folks involved with C4MVC, recently wrote a blog post on posting JSON (JavaScript Object Notation) encoded data to an MVC controller action. In his post, he describes an interesting approach of using a custom model binder to bind sent JSON data to an argument of an action method. Responsive design using Foundation with ASP.Net MVC. Responsive design is a technique for creating a website or web application that can adapt to a client’s screen or interface.

Responsive design using Foundation with ASP.Net MVC

In responsive design a flexible layout, together with flexible content and media queries, is used to change how the page is rendered on the client’s screen. Although the basics of responsive design on the surface are simple, there are many design challenges. By using a framework, you can enter the design process better prepared to meet these challenges.

One framework that I prefer to use is Foundation Framework by Zurb. Not only is Foundation a great asset, but it’s also an excellent learning tool because many of the problems of responsive design are solved in an organized and well thought-out manner. Foundation, as the name suggests, provides a base for starting a new responsive design project. Foundation basics. Brad Wilson ASP.NET MVC 2 Templates, Part 4 Custom Object Templates. Series Index Customizing Templates In Part 3, we saw what the default templates would look like if we’d written them as .ascx files.

Brad Wilson ASP.NET MVC 2 Templates, Part 4 Custom Object Templates

In this blog post, we’ll discuss some of the customizations you can make to the Object templates to enable different features and different displays for your template-based UI. For these examples, here are the models, controller, and views that we’ll be using. ASP.NET MVC 4 - Implementing Asynchronous controller using .NET Framework 4. Most web developers know about ASP.NET’s request processing pipeline.

An HTTP request is synchronously processed on a Thread which is grabbed from the ThreadPool. The Thread on which this request is processed is blocked from doing anything else like handling another incoming request. This scenario can be really problematic for large number of concurrent requests. If the server is busy processing all these synchronous requests, the ‘Server Busy’ status code is send to the client.

MVC Extensions

Rendering ASP.NET MVC Views to String. It's not uncommon in my applications that I require longish text output that does not have to be rendered into the HTTP output stream. The most common scenario I have for 'template driven' non-Web text is for emails of all sorts. Logon confirmations and verifications, email confirmations for things like orders, status updates or scheduler notifications - all of which require merged text output both within and sometimes outside of Web applications. On other occasions I also need to capture the output from certain views for logging purposes. Rather than creating text output in code, it's much nicer to use the rendering mechanism that ASP.NET MVC already provides by way of it's ViewEngines - using Razor or WebForms views - to render output to a string.

<% %> in ASP.NET (embedded code blocks) Embedded Code and Inline Server Tags - Ahmed Moosa. Introductions Hi, this my first article here and I hope it will be more useful , so we will talk about something we need to use every day in coding ,we will talk about "Embedded Code " using "In line Server Tags " . Briefly it used to write server side code somewhere where it not allowed directly . more developers use it in data binding controls .but you can use it in many Places Like (Java Script , CSS , ASPX ) , and you can use it with Routing ,ConnectionStrings , XMLQuery , AppSettings , Recourses Files or just writing server side code mixed with html. my be you had seen it in the top of .aspx page .OK ! Let us begin . Download sample Code from Here What In line Server Code is ? [ASP.NET MVC] Views – ASPX View (WebFormViewEngine) January 8, 2012 at 2:49 pm In ASP.Net MVC applications, a View is returned by a controller action. A view contains the HTML markup and content that is sent back to the user.

MVC3 introduced a new view syntax (Razor), which you want and need to use. But this post will describe the legacy ASPX view syntax. Simple-Talk : Web Developers. A Different Approach to Validation in ASP.NET MVC Sites. Validation support in modern ASP.NET MVC projects is phenomenal. I love how easy it is to declaratively validate my models through meta-data validation attributes. Not only does the framework easily handle everything once I validate my models, but it also cleanly leverages jQuery validation for simple and unobtrusive client-side validation. For more information on jQuery, see "6 Reasons Why jQuery Is a Great Framework" and "4 More Web Development Tips to Improve Your jQuery Coding.

" In fact, I enjoy these validation mechanisms so much that I've used them to tweak the default ASP.NET MVC convention of checking whether my models are valid. Although my reasoning will require some explanation, I think my process results in a cleaner workflow. An Exception-Driven Approach to Validation Although it's natural for any .NET developer to freak out about excessive exception use, the reality is that an exception thrown here or there doesn't actually pose any problems. Public SignupViewModel() {} Web Essentials 2012 extension. Dropping support for TypeScript (without plastering that "little" detail all over the download page) has just cost me 4 wasted hours and sent me full circle back to the old Web Essentials. ASP.NET MVC 3 : Creating Custom HTML Helpers - ASP.NET Wiki.

Written by John DeVight on 2011-Jun-13 Download RAZOR Source Code Download ASPX Source Code. ASP.NET MVC 3 : Creating a Custom HTML Helper to Render List of Models as a Table - ASP.NET Wiki. ASP.NET MVC ImageLink HTML Helper. ASP.NET MVC Tutorial: Handling Errors and Exceptions. Partial Requests in ASP.NET MVC.

AttributeRouting.