1

I use this razor code to generate a HTML button that calls a function with a value from the model:

Html.Raw(string.Format("<button type='button' class='btn btn-success btn-xs' onclick='setCoordinatorForService('{0}')'>Åta</button>", item.Name))

The value of item.Name is "abc", the code:

<button type="button" class="btn btn-success btn-xs" onclick="setCoordinatorForService(" abc')'="">Åta</button>

I want this:

<button type="button" class="btn btn-success btn-xs" onclick="setCoordinatorForService("abc")'="">Åta</button>

What am i doing wrong?

1
  • 1
    How about setCoordinatorForService(\"{0}\")? Commented Apr 16, 2014 at 14:22

1 Answer 1

6

You must replace ' to \"

If you use this code, probably it works very well.

Html.Raw(string.Format("<button type=\"button\" class=\"btn btn-success btn-xs\" onclick=\"setCoordinatorForService('{0}')\">Åta</button>", item.Name)))

Besides the line you wanted it has error.

onclick="setCoordinatorForService("abc")'=""

part maybe give an error because of =

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.