希望你偷看可以帮我解决问题。
代码问题: 将完成的用户表单中输入的数据传递给控制器中的方法,该方法将值发回到api,同时加载包含提交数据的模态。
我的问题: 香港专业教育学院试图找到解决上述问题的方法,但我不认为发布请求是在firefox中使用firebug检查后发送的,但我不知道为什么。显示模态,并在正确的体内显示值。
这是我到目前为止所拥有的:
Bootstrap Form:
<form action="/Home/PostData" method="post" class="form-horizontal">
<div class="form-group">
<label class="control-label col-xs-2" for="imei">IMEI:</label>
<div class="col-xs-9">
<input type="text" class="form-control" id="imei" name="formpart" placeholder="IMEI">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-2" for="phoneNumber">Phone Number:</label>
<div class="col-xs-9">
<input type="tel" class="form-control" id="phoneNumber" name="formpart" placeholder="Phone Number">
</div>
</div>
<div class="form-group">
<label for="platform" class="control-label col-xs-2">Policy Organisation:</label>
<div class="col-xs-10">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
<span id="dropdown_title1">Select</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" id="dropdownMenu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">TMT Internals</a></li>
</ul>
</div>
</div>
</div>
<div class="form-group">
<label for="policyNumber" class="control-label col-xs-2">Policy Number:</label>
<div class="col-xs-10">
<input type="text" class="form-control" id="policyNumber" name="formpart" placeholder="Policy Number">
</div>
</div>
<div class="form-group">
<label for="platform" class="control-label col-xs-2">Platform:</label>
<div class="col-xs-10">
<div class="dropdown">
<button class="btn btn-default" id="dropdownMenu2" data-toggle="dropdown">
<span id="dropdown_title2">Select</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" id="dropdownMenu2">
<li><a tabindex="-1" href="#">Android</a></li>
<li><a tabindex="-1" href="#">IOS</a></li>
<li><a tabindex="-1" href="#">Windows Phone</a></li>
</ul>
</div>
</div>
</div>
<div class="form-group">
<label for="diagnosticMode" class="control-label col-xs-2">Diagnostic Mode:</label>
<div class="col-xs-10">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu3" data-toggle="dropdown">
<span id="dropdown_title3">Select</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" id="dropdownMenu3">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Simple</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Advanced</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Mannual</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Complete</a></li>
</ul>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-2 col-xs-10">
<button type="submit" id="SendRequest" class="btn btn-success">Create New Request</button>
<button class="btn btn-primary">Back to List</button>
</div>
</div>
</form>
控制器方法:
public ActionResult PostData()
{
using (WebClient client = new WebClient())
{
System.Collections.Specialized.NameValueCollection reqparm = new System.Collections.Specialized.NameValueCollection();
reqparm.Add("IMEI", Request["#imei"].ToString());
reqparm.Add("PhoneNumber", Request["#phoneNumber"].ToString());
reqparm.Add("PolicyNumber", Request["#policyNumber"].ToString());
reqparm.Add("SupportUserId", Session["UserId"].ToString());
reqparm.Add("PolicyOrganisationId", Request["#dropdown_title1"].ToString());
reqparm.Add("PlatformFamilyInfoId", Request["#dropdown_title2"].ToString());
reqparm.Add("AppModeId", Request["#dropdown_title3"].ToString());
byte[] responsebytes = client.UploadValues("**removed url for security purposes**", "POST", reqparm);
string responsebody = Encoding.UTF8.GetString(responsebytes);
}
return View("something");
}
Jquery(将值传递给模态)
// captures user entered data
$("#SendRequest").click(function () {
var imei = ("IMEI: " + $("#imei").val());
$('#printImei').html(imei);
var phonenumber = ("Phone Number: " + $("#phoneNumber").val());
$('#printPhoneNumber').html(phonenumber);
var policyorganisation = ("Organisation: " + $("#dropdown_title1").text());
$('#printPolicyOrg').html(policyorganisation);
var policynumber = ("Policy Number: " + $("#policyNumber").val());
$('#printPolicyNumber').html(policynumber);
var platform = ("Platform: " + $("#dropdown_title2").text());
$('#printPlatform').html(platform);
var diagmode = ("Diagnostic Mode: " + $("#dropdown_title3").text());
$('#printDiagnosticMode').html(diagmode);
});
点击“创建新请求”后显示的模式:
<div class="modal fade" id="basicModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">Summary</h4>
</div>
<div class="modal-body">
<span id="printImei"></span><br />
<span id="printPhoneNumber"></span><br />
<span id="printPolicyOrg"></span><br />
<span id="printPolicyNumber"></span><br />
<span id="printPlatform"></span><br />
<span id="printDiagnosticMode"></span>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>