2

I am developing an ASP .Net MVC 3 application using C# and SQL Server 2005.

I am using also Entity Framework and Code First Method.

In a view, I have 2 checkbox and DropDownList.

I want when I check the checkbox, the DropDownList and the other checkbox became DISABLED.

I use a javascript in order to do that.

The checkbox is perfect , it became disabled but I still have a problem with DropDownList.

This is the code :

<div>
<input type="checkbox" name="option1" value="Poste Initial" id= "chkMain" />Poste Initial<input type="checkbox" name="option2" value="Poste Final" id= "chkFirst" onclick="test2();"/>Poste Final</div>

<div><%:Html.Label("Poste Suivant :")%><%: Html.DropDownListFor(model => model.PosteSuivantSelected, Model.PostesItems); ID = "dd"%></div>

<script type="text/javascript">

         function test2() {
             var chkMain = document.getElementById('chkMain');
             var chkFirst = document.getElementById('chkFirst');
             var dd = document.getElementById('dd');

             if (chkFirst.checked) {
                 chkMain.disabled = 'disabled';
                 dd.disabled = 'disabled';

             }
             else {
                 chkMain.disabled = false;

             }
         }

    </script>

I had a Compilation Error in the line of DropDownList

2
  • 1
    Can you post any details of the error? Commented May 22, 2013 at 9:42
  • Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS1026: ) expected Source Error: <div><%:Html.Label("Poste Suivant :")%><%: Html.DropDownListFor(model => model.PosteSuivantSelected, Model.PostesItems); ID = "dd"%></div> Commented May 22, 2013 at 9:44

1 Answer 1

4
<%: Html.DropDownListFor(
    model => model.PosteSuivantSelected, Model.PostesItems); ID = "dd"%>

This is invalid syntax. If you wish to assign an id to the dropdown list, then use an anonymous type:

Html.DropDownListFor(
    model => model.PosteSuivantSelected, Model.PostesItems, new { @id = "dd" });
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.