Chapter 6. Working with Forms

In this chapter, we will cover:

  • Using HTML helpers to create forms
  • Building a custom HTML helper to display a WYSIWYG
  • Centralizing create and edit forms for reuse
  • Adding custom attributes to form elements
  • Defining a default button using jQuery
  • Hijaxing a form with jQuery
  • Performing an auto postback with a select list
  • Autocomplete with jQuery UI

Introduction

One of the big advantages that ASP.NET MVC has over web forms is the ease with which you can work with forms. In this chapter, I'll take you from the basics of setting up a form using HTML helpers to more advanced concepts such as autocomplete.

I'd suggest looking at the first recipe before jumping further into the chapter, as I'll be using the project created there as a baseline for all of the other recipes.

The majority of the recipes in this chapter will need a model to work with. To make life easier, I have created a simple Article class, which will help demonstrate the different ways in which ASP.NET MVC deals with data types.

Models/Article.cs:
public class Article {
public Guid ID { get; set; }
public string Title { get; set; }
public string Subject { get; set; }
public string Description { get; set; }
public DateTime CreateDate { get; set; }
public bool IsPublished { get; set; }
public int TimesViewed { get; set; }
public string FormattedCreateDate
ASP.NET MVCASP.NET MVCdata types, dealing with{
get
{
if(CreateDate != DateTime.MinValue)
return string.Format("{0:d/M/yyyy HH:mm:ss}", CreateDate);
return "";
}
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset