How can I implement the following Scenario:
I would like to have a signup wizard that creates the userProfile account. In that form I have a companyName (required). I will then take that companyName and start a record in the companyInfromation Table. All of the columns in this table should be nullable since I am starting the record on user signup.
After the user signs up they are prompted that they are required to finish filling out the company information, so they are taken to the company information form.
now here is my question, how can I make this form have required attributes and make the user fill out all of the required information? (Not just JavaScript but also modelState validation) I thought about a viewModel but I’m getting a bunch of “cannot convert the type ‘project.model.companyinformation’ to project.model.companyinformationviewmodel'” error.
I’m very new to C#, asp.net MVC. I used to just take the easy way out and use vb.net and asp.net webforms.
Any help would be greatly appreciated.
Creating a model is the correct approach. You can’t cast from entity to model. You need to transfer the data yourself.
There’s a useful project called AutoMapper that can automate this for you.
An alternative approach is to create a custom validation attribute
RequiredIf. This would validate if a specified boolean field has a value of true: