【发布时间】:2015-12-05 11:46:54
【问题描述】:
在视图中我有一个表单:
<div>
@using (Html.BeginForm(null, null, new { id = "TCPForm" }))
{
<h4>Request</h4>
@Html.TextBoxFor(m => m.HttpRequest, new {name="HttpRequest"})
<h4>Port Nunber</h4>
@Html.TextBoxFor(m => m.HttpPortNumber, new { name ="HttpPortNumber"})
@Html.RadioButtonFor(model => model.HttpRequestType, HttpRequestType.Get, new {@Id = "get"})
<label for="get">Get</label>
@Html.RadioButtonFor(model => model.HttpRequestType, HttpRequestType.Post, new {@Id = "post"})
<label for="post">Post</label>
}
<p></p>
<input type="submit" id="TCPSubmit" value="Send Request" />
</div>
提交按钮在表单之外,因为我使用 jQuery 拦截它。
然后我有这个 Jquery 来拦截按钮按下,显示一个微调器并通过 Ajax 获取结果:
$('#TCPSubmit').click(function () {
$('#resultPaneTCP').html("<div class='spinner'><div class='dot1'></div><div class='dot2'></div></div>");
$.ajax({
url: "@Url.Action("SendTcpMessage", "TestandDevelopment")",
type: "POST",
data: $('#TCPForm').serialize(),
datatype: "text",
success: function (data) {
$('#resultPaneTCP').html(data);
}
});
return false;
});
这是动作签名:
public ActionResult SendTcpMessage(HttpViewModel httpViewModel)
{
这是我发送到视图并在表单中进行编辑的模型:
public class HttpViewModel
{
public string HttpRequest { get; set; }
public string HttpResponse { get; set; }
public string HttpRequestType { get; set; }
public string HttpPortNumber { get; set; }
public HttpViewModel()
{
}
public HttpViewModel(string httpRequest, string httpResponse)
{
this.HttpRequest = httpRequest;
this.HttpResponse = httpResponse;
}
}
当我运行上述程序并按下视图中的按钮时,会显示微调器,触发动作但动作签名中的模型是空的。
我做错了什么?
【问题讨论】:
标签: jquery razor model-view-controller