I have a few textboxes that are not required. If the user enters nothing it is passed as ‘null’ in MVC 2. It was passed as ‘””‘ in MVC 1. What changes can I make to accomodate for this?
public string Name { get; set; }
public string Offer{ get; set; }
public string AutoID { get; set; }
using (SqlConnection connect = new SqlConnection(connections))
{
SqlCommand command = new SqlCommand("Info_Add", connect);
command.Parameters.Add("autoID", SqlDbType.BigInt).Direction = ParameterDirection.Output;
command.Parameters.Add(new SqlParameter("name", Name));
//Offer now returns a null value, which cannot be passed
command.Parameters.Add(new SqlParameter("offer", Offer));
command.CommandType = CommandType.StoredProcedure;
connect.Open();
command.ExecuteNonQuery();
AutoID = command.Parameters["autoID"].Value.ToString();
}
Check the properties with
string.IsNullOrEmpty()and if its true then set some default value to it.This way it works both for ASP.NET MVC 1 and ASP.NET MVC 2