Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an asp.net application and i need to combine C# and javascript code:

<td >
    <label name="tag@(i)">@Model[1][i]._tag</label>
</td>
<td>
    <input type="text" value="@Model[1][i]._client" name="client@(i)"/>
</td>
<td>
    <input type="text" value="@Model[1][i]._reception"  class="datepicker" name="reception@(i)"/>
</td>
<td>
    <input type="text" value="@Model[1][i]._cloture"  class="datepicker" name="cloture@(i)"/>
</td>
<td>
    @{
        List<Planning.Models.Impaire> liste = u.Get_Impaire_List();
        Planning.Models.Impaire imp = liste.Find(x => x.id_paire == Model[1][i].Id);

        @{
            string reception =  @: <script>
            @: var f1 = $('input[name="reception' + @i.ToString() + '"]').val();
            @: document.write(f1);
            @: </script>
            ;
            string cloture =  @: <script>
            @: var f2 = $('input[name="cloture' + @i.ToString() + '"]').val();
            @: document.write(f2);
            @: </script>
            ;
            string client =  @: <script>
            @: var f3=  $('input[name="client' + @i.ToString() + '"]').val();
            @: document.write(f3);
            @: </script>
            ;
            string tag =  @: <script>
            @:var f4= $('input[name="tag' + @i.ToString() + '"]').val();
            @: document.write(f4);
            @: </script>
            ;
        }

        @Html.ActionLink("enregistrer","Index", new {identificateur = Model[1][i].Id, Pages = "1", _reception =reception, _cloture = cloture, _client = client, _tag = tag  })
    </td>  

But I have an exception in this line : @: var f1 = $('input[name="reception' + @i.ToString() + '"]').val(); error

What are the reasons of this error? How can I fix it?

share|improve this question
 
did you have suggestions? –  Lamloumi Oct 7 '13 at 21:12
add comment

1 Answer

up vote 1 down vote accepted

Having js inside the view like your sample is highly unlucky and can always be avoided. Find a way to separate javascript from razor code as good as you can. You could leave javascript variables inside the view alike

var arr = [@i.ToString()]

and then, in a separate js file you process this js variable arr.

share|improve this answer
 
i got the same result in adding var arr = [@i.ToString()] –  Lamloumi Oct 7 '13 at 21:21
1  
the error message in the image is not readable, since it is 1. too small, 2nd in french, which I am not too good at. Looks like your template code is invalid. Maybe cut out parts until it works to find where it hangs. –  citykid Oct 7 '13 at 21:24
 
Compilation error Description: An error occurred during the compilation of a resource required to meet this demand. Please see below the details of the error in question and modify your source code appropriately. Compiler Error Message: CS1002:; expected –  Lamloumi Oct 7 '13 at 21:26
1  
Well that is a syntax error in the template code. That should be easy to find, as said, cut out pieces of teplate code and you should find it. –  citykid Oct 7 '13 at 21:28
 
but the same shared template didn't caused an mistakes in the other views. Why this one ? –  Lamloumi Oct 7 '13 at 21:32
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.