0

I have the following code inside my asp.net mvc view:-

@Html.DropDownListFor(model => model.FirewallCustomer.CustomerVLANSID,null, null, null)
@Html.ValidationMessageFor(model => model.FirewallCustomer.CustomerName)
<div><span class="f">VLAN IP</span> @Html.TextBox("VLANIP", new { disabled = "disabled"})</div>

but the above code will raise an error on the DropDownListFor:-

There is no ViewData item of type 'IEnumerable' that has the key 'FirewallCustomer.CustomerVLANSID'.

and for the TexBox it will show the disabled = "disabled" inside the textbox body, instead of disabling it. can anyone adivce on how to solve my dropdownlist & my textbox problems??? Thanks`

2
  • 1
    in DropDownListFor try passing an empty values list, but not null Commented Nov 15, 2013 at 0:22
  • 1
    for TextBox: read its conctructor signature, you're putting html attribtes in the wrong place Commented Nov 15, 2013 at 0:24

1 Answer 1

3
  • For textbox

@Html.TextBox("VLANIP", new { disabled = "disabled"}) change to

@Html.TextBox("VLANIP","Your Value", new { disabled = "disabled"}) . I would like to advise you change disabled = "disabled" to @readonly = "readonly".

  • For dropdown list, if you wanna create a empty dropdownList for, you have to convert you FirewallCustomer.CustomerVLANSID to SelectListItem and add empty value for it. Please post your action for this view, i can help you. Should try

    Html.DropDownListFor(model => model.FirewallCustomer.CustomerVLANSID,Enumerable.Empty< SelectListItem >(),null)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.