我有一个部分观点,我在以下页面上调用:-
@Html.Partial("~/Views/Shared/ImageGallery.cshtml", Model)
此页面实际 Jquery 的代码如下:-
<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>
现在这完美无缺,但是我需要找到一种方法将动态变量而不是硬编码变量传递给它:-
Upload/UploadImage?Page=Article&Action=Edit&id=16
在模型中我有所有的变量,但是我不知道如何将它们插入到 Jquery 中。任何帮助将不胜感激!
- - - - -更新 - - - - - - - - - - - -
这是我放入每个需要 ImageGallery 的 cshtml 的代码。
</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>
ImageGallery 中的新 Javascript:-
<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>
现在工作正常