MVC DropDown List in Form from EF

Hi:

I am trying to create a form based on a couple of classed from Entity Framework.  Basically, what I want to do is for the form to have a firstname and lastname text boxes and a dropdown list of organizations to which the user could belong.  I also want to make the text boxes disabled - i.e. visible but user not able to do anything.

Here are my two classes:

public class UserProfile
{
	[Key]
	public int UserId { get; set; }

	[MaxLength(50)]
	public string FirstName { get; set; }

	[MaxLength(50)]
	public string LastName { get; set; }
	
	public int OrgId { get; set; }
	public virtual Org Orgs { get; set; }
}
	
public class Org
{
	public int OrgId { get; set; }
	public string Name { get; set; }
}

Open in new window


My form has the following markup:
@model CodeCamper.Web.Models.ManageContactInfoViewModel

<h2>Manage Contact Info</h2>

@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<div class="well form-horizontal span12">
    <fieldset>
        <legend></legend>
		@*How do I make this disabled?*@
        <div class="control-group">
            @Html.LabelFor(m => m.UserProfile.FirstName, new { @class = "control-label" })
            <div class="controls">
                <input id="FirstName" name="FirstName" type="text" value="" />
                @Html.ValidationMessageFor(model => model.UserProfile.FirstName, null, new { @class = "help-inline" })
            </div>
        </div>
		
		@*How do I make this disabled?*@
        <div class="control-group">
            @Html.LabelFor(m => m.UserProfile.LastName, new { @class = "control-label" })
            <div class="controls">
                <input id="LastName" name="LastName" type="text" value="" />
                @Html.ValidationMessageFor(model => model.UserProfile.LastName, null, new { @class = "help-inline" })
            </div>
        </div>

	@*How do I make this a dropdown without compiler errors?*@
        <div class="editor-field">
            @Html.DropDownListFor(model => model.UserProfile.Orgs, null, new {  @class = "help-inline" })
            @Html.ValidationMessageFor(model => model.UserProfile.Orgs)
        </div>

        <div class="form-actions">
            <button class="btn btn-large btn-inverse">Cancel</button>
            <input class="btn btn-primary btn-large" type="submit" value="Send" />
        </div>

    </fieldset>
</div>

Open in new window


The compiler gives me the error "There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'UserProfile.Orgs'"

I would appreciate any help on this and also getting the first and lastname textboxes disabled.

RBS
RBSAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
This property is not a list or IEnumerable<T>:

public virtual Org Orgs { get; set; }
0
RBSAuthor Commented:
How would I make this property a list or IEnumerable<t> in this context?
0
Bob LearnedCommented:
My guess:

public virtual List<Org> Orgs { get; set; }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RBSAuthor Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.