I'd to set a local javascript variable to the output of an html helper. See the following snippet for an example:
<script type="text/javascript">
$(function () {
var dtypes = '@Html.DropDownList("TypeId",new SelectList(@ViewBag.MyTypes,"Value","Text"))';
});
alert(dtypes);
</script>
This doesn't give me an alert. Am I doing something wrong? Thanks for any help.
@Html.DropDownListproduces HTML markup for a<select>element. What exactly are you trying to achieve here?DropDownListmethod will put in some new lines into its output so your string is unterminated. You will likely have to create your own extension method to make this work. Or, better yet, why have the HTML markup in a Javascript object?