本文介绍了将数据从文件.cs或cshtml文件的值发送到js MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题.例如:我有student.cs和student.cshtml.我需要获取student.cs或student.cshtml的数据才能进行control.js在MVC中.该怎么做?

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?

推荐答案

我相信您在问如何从View(student.cshtml)或Controller(student.cs(应命名为StudentController.cs)中获取数据)到一个JavaScript文件(control.js),以便在Javascript中对其进行操作.

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.

我完成此操作的方法是使用隐藏的div通过View.这是一个通用示例:

The way I've done this is through the View using a hidden div. Here is a generic example:

查看:

<div style="display: none;" id="uniqueDivIdName" data-id="@JsonConvert.SerializeObject(@Model)" />
<script src="~/Scripts/control.js "></script>

Javascript:

Javascript:

var dataFromView = $("#uniqueDivIdName").data("id");

这篇关于将数据从文件.cs或cshtml文件的值发送到js MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 15:52