【发布时间】:2017-11-14 11:57:01
【问题描述】:
我的情况是,我想使用 JQuery 从页面中获取一个值,用该值更新模型,调用一个方法来更新模型中的不同值。然后调用控制器返回一个带有新模型的视图。
我是新手,所以我认为这是错误的方法。
这是我目前的观点:
@using Cubic.OSS.SNMPMessageDuggerWebApplication.Models
@model SnmpModel
@{
ViewBag.Title = "SNMP Message Debugger";
}
@section scripts
{
<script src="~/Scripts/jquery-1.7.1.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#input-button").click(function () {
// This is where I want the process to start.
});
});
</script>
}
<h2>@ViewBag.Title.</h2>
<div class="container-bar">
<div id="input-bar">
<p class="input-label">Enter SNMP Message: </p>
<textarea rows="10" cols="300" id="input-area"></textarea>
<br />
<button id="input-button">Convert</button>
</div>
<div id="output-bar">
<p class="output-label">Result: </p>
<textarea rows="10" cols="300" id="output-area"></textarea>
</div>
</div>
我的模型如下所示:
public class SnmpModel
{
public string SnmpMessageInput { get; set; }
public string SnmpMessageOutout { get; set; }
// I Imagine a method would be added here to transform the input
}
这是目前为止的控制器:
public class SNMPController : Controller
{
// GET: SNMP
public ActionResult Index()
{
return View();
}
}
我不知道该怎么做:用返回的 JQuery 更新模型,然后使用控制器用新模型刷新页面。
输入将从输入文本区域获取,然后使用之前用 C# 编写的代码进行转换。这将是我想象的模型中的一种方法。我必须使用用C#编写的代码,所以我不能在js中做算法。
谢谢。
【问题讨论】:
标签: c# jquery asp.net asp.net-mvc razor