我是ASP.NET MVC的新手。我想读取div的textContent并将该值存储在C#服务器的变量中,以基于该值进行进一步的计算。
例如:
查看侧
<div class="target" id="div1">
<div>Start</div>
<div>Process 1</div>
<div>Process 2</div>
<div>Process 3</div>
<div>Stop</div>
</div>
控制器端
public ActionResult Index()
{
var list = /*Read the text content of the div1 */
for(int i=0;i<list.length;i++)
{
switch(list[i])
{
case "Process 1":
//do some tasks
break;
case "Process 2":
//do some task
break;
}
}
return View();
}
在此先感谢您的帮助。
答案 0 :(得分:0)
经过研究,我发现这可以满足我的要求:
jQuery.ajax({
type: "POST",
url: "@Url.Action(<actionName>, <controllerName>)",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ <variableToSend> }),
success: function(data) {
alert(data);
},
failure: function(errMsg) {
alert(errMsg);
}
});