i have a question. Ex : I have student.cs , student.cshtml . I need get data of student.cs or student.cshtml to control.js in MVC. how to do that?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I believe you're asking how to get data from either the View (student.cshtml) or Controller (student.cs (should be named StudentController.cs)) to a JavaScript file (control.js) to manipulate it in Javascript.
The way I've done this is through the View using a hidden div. Here is a generic example:
View:
<div style="display: none;" id="uniqueDivIdName" data-id="@JsonConvert.SerializeObject(@Model)" />
<script src="~/Scripts/control.js "></script>
Javascript:
var dataFromView = $("#uniqueDivIdName").data("id");