1

My Controller is...

public ActionResult CreateEmailStep5()
{
    MyViewModel mvm = new MyViewModel();
    mvm.myStringProperty = @"$(document).ready(function ($) {
        $('#Help').MyTour(
        {
          tourType: 'step',
          overlayOpacity: 0.5,
          .......
          .......
        });
    });"
    return View(mvm);
}

what am i trying with my .cshtml is like....

@model MyProj.ViewModels.MyViewModel
<script type="text/javascript">
    Model.myStringProperty;
</script>

I tried several things like Response.Write, HtmlDecode and HtmlEncode... what happening is... My Single Quote is being converted to its ascii " ' "

when i am trying...

Response.Write(@HttpUtility.HtmlDecode(Model.myStringProperty).ToString());

instead of

Model.myStringProperty;

in my .cshtml then its giving erro $ is not defined while i have added all required links

4
  • Why are you dynamically building the javascript in your view? Do you intend to pass some values to your javascript? Commented May 6, 2013 at 11:32
  • i need it because i don't know how much step i need to implement.. this info will come from DataBase Commented May 6, 2013 at 11:33
  • let me know if there is a way to do like this Commented May 6, 2013 at 11:34
  • basically i need to create javascript function Dynamically on server an then i want to inject it to .cshtml.... Commented May 6, 2013 at 11:36

1 Answer 1

1

You want to convert your razor variable to html 'type'

Try using

@Html.Raw(Model.myStringProperty)
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.