I have a partial view that I invoke on the pages as follows: -
@Html.Partial("~/Views/Shared/ImageGallery.cshtml", Model)
The code for the actual jquery of this page is as follows: -
<script type="text/javascript">
$(document).ready(function () {
$('.modal_block').click(function (e) {
$('#tn_select').empty();
$('.modal_part').hide();
});
$('#modal_link').click(function (e) {
$('.modal_part').show();
var context = $('#tn_select').load('/Upload/UploadImage?Page=Article&Action=Edit&id=16', function () {
initSelect(context);
});
e.preventDefault();
return false;
});
});
</script>
Now this works great, however I need to find a way to pass dynamic vars instead of hard-coded vars: -
Upload/UploadImage?Page=Article&Action=Edit&id=16
I have all the vars in the model, however I don’t know how I can insert them into jQuery. Any help would be greatly appreciated!
--------- UPDATE -----------------------
This is the code that I put in every cshtml that ImageGallery needs.
</div>
@Html.HiddenFor(model => model.PageViewModel.Page.PageTitle, new { id = "PageTitle"});
@Html.HiddenFor(model => model.PageViewModel.Page.PageAction, new { id = "PageAction"});
@Html.HiddenFor(model => model.ArticleViewModel.Article.ArticleID, new { id = "ArticleID"});
<div>
@Html.Partial("~/Views/Shared/ImageGallery.cshtml", Model)
</div>
New Javascript in ImageGallery: -
<script type="text/javascript">
var pageTitle = $('#PageTitle').val();
var pageAction = $('#PageAction').val();
var id = $('#ArticleID').val();
$(document).ready(function () {
$('.modal_block').click(function (e) {
$('#tn_select').empty();
$('.modal_part').hide();
});
$('#modal_link').click(function (e) {
$('.modal_part').show();
var context = $('#tn_select').load('/Upload/UploadImage?Page=' + pageTitle + '&Action=' + pageAction + '&id=' + id, function () {
initSelect(context);
});
e.preventDefault();
return false;
});
});
</script>
Now it works great