我需要将业务类属性值获取到 java 脚本变量。使用该值我正在做一些操作。在这里,我尝试在 aspx 页面中创建对象和字符串,但无法访问 Java 脚本中的字符串“val”。如何访问它?
.aspx 文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<% WebApplication1.Business obj = new WebApplication1.Business(); %>
<% string val = obj.Name; %>
<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function () {
$("#btnSubmit").click(function(){
alert("welcome");
var valProperty = <%= val%>;
alert("Val Property is : "+ valProperty);
$("#txtName").val(valProperty);
});
});
</script>
<form id="form1" runat="server">
<div>
<input type="text" id="txtName" />
<br />
<input type="button" id="btnSubmit" value="Get Server Property Value" />
</div>
</form>
</body>
</html>
类文件:
public class Business
{
public string Name { get; set; }
public string Money { get; set; }
}