4

I am having the following piece of code that is not working:

<a href="#" onclick="Edit(@Interest);">edit</a>

where I have

@{string Interest=""}

2 Answers 2

6

You need to quote the string like this:

<a href="#" onclick="Edit('@Interest');">edit</a>
Sign up to request clarification or add additional context in comments.

2 Comments

it`s firing error with Edit('@Interest'); error CS0165: Use of unassigned local variable 'Interest'
The compiler is probably right - assign a value before using the variable.
1

If you want to call a method e.g. @Url.Action("test") for an action link, then you have to use it like:

<a href='@(Url.Action("test"))'>test</a>

Otherwise korchev's solution is right.

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.