Implementing Custom Profile Provider in ASP.NET MVC

前端 未结 2 503
刺人心
刺人心 2020-12-09 13:46

I tried a lot on implementing a custom profile provider in ASP.NET MVC. I\'ve read lots and lots of tutorials, but I can\'t find where my problem is. It\'s pretty similar to

2条回答
  •  无人及你
    2020-12-09 14:00

    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

提交回复
热议问题