In this controller i got all the movienames
public ActionResult MultiText()
{
List<string> mnames = db.AllMovienames().ToList();
ViewBag.movies = mnames;
return View();
}
I need to send this "ViewBag.movies" to Javascript present in view
$(function () {
var availableTags = ViewBag.movies;
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
$("#tags")
// don't navigate away from the field on tab when selecting an item
.bind("keydown", function (event) {
if (event.keyCode === $.ui.keyCode.TAB &&
$(this).data("ui-autocomplete").menu.active) {
event.preventDefault();
}
})
But i cant get values into view
You could write it out as json in your view like this:
<script type="text/javascript">
var movies = @Html.Raw(Json.Encode(ViewBag.movies))
</script>
If you wrap your javascript up into a function you could then pass them in i.e.
function DoThis(movies)
{
var availableTags = movies;
.....
}
This would allow you to call it like this:
<script type="text/javascript">
var movies = @Html.Raw(Json.Encode(ViewBag.movies))
DoThis(movies);
</script>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments