0

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?

1
  • did you have suggestions? Commented Oct 7, 2013 at 21:12

1 Answer 1

1

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.

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

6 Comments

i got the same result in adding var arr = [@i.ToString()]
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.
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
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.
but the same shared template didn't caused an mistakes in the other views. Why this one ?
|

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.