A: 

I have yet to mess with ASP.NET MVC, but I've noticed that you have no properties defined in your web.config.

<profile>
  <properties>
    <add name="FirstName" type="string" defaultValue="[null]"
            customProviderData="FirstName;nvarchar" />
  </properties>
</profile>
bryan_cook
In MVC (and Web Applications generally) you can't provide properties like this. You have to inherit from a class you write rather than the Web Site method of having the ProfileCommon class generated for you.
WooWaaBob
A: 

Yeah, it's because I'm using a class for my properties, ProfileCommon that inherits from ProfileBase.

public class ProfileCommon : ProfileBase
{
public virtual string Label
{
 get
 {
  return ((string)(this.GetPropertyValue("Label")));
 }
 set
 {
  this.SetPropertyValue("Label", value);
 }
}

public virtual string FirstName
{
 get
 {
  return ((string)(this.GetPropertyValue("FirstName")));
 }
 set
 {
  this.SetPropertyValue("FirstName", value);
 }
}

public virtual string LastName
{
 get
 {
  return ((string)(this.GetPropertyValue("LastName")));
 }
 set
 {
  this.SetPropertyValue("LastName", value);
 }
}

public virtual ProfileCommon GetProfile(string username)
{
 return Create(username) as ProfileCommon;
}
}

You can see that I'm using this class in the Web.Config file:

<profile enabled="true"
     automaticSaveEnabled="false"
     defaultProvider="UserProfileProvider"
     inherits="Test.Models.ProfileCommon">
[...]

And with ASP.Net MVC, if I wrote my properties in Web.Config, I cannot access them using Profile.PropertyName anymore. Maybe there's a way, but I don't find any examples.

Flesym
+1  A: 

The most likely cause is that

myCommand.Parameters.AddWithValue("@FirstName", (string)context["FirstName"]);

(string)context["FirstName"] is a null value. Even if you pass in a parameter to a sproc, if the value is null on a required parameter, then you will see this error. SQL Server (effectively) does not differentiate between a parameter not passed, and one passed with a null value.

You're seeing a SQL error. This is unrelated to MVC and MVC isn't really causing your problem. Determine if null is a valid value context["FirstName"], and if so, change your function to accept null values. If not, find out why context["FirstName"] is null.

Also, I don't think this line is going to add your parameter names correctly (with the "@" prefix).

myCommand.Parameters.AddWithValue(value.Name, value.PropertyValue);

Also, since this is MVC, make sure you have a control named FirstName on the form posting to:

public ActionResult CreateProfile(string Username, string Password, string FirstName, string LastName)

It reads fields based on the name, not the ID

Russell Steen