我想要一个可以输入贷款号码的页面,然后我将调用 WCF 获取服务来查看贷款号码是否有效。如果贷款# 有效,我想在同一页面上显示贷款相关数据(部分视图)。
这是我的主要观点:
@model LoanStatus.Web.Models.Validate
@{
ViewBag.Title = "Validate";
}
@section Scripts {
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/jqueryui")
}
<script type="text/javascript">
jQuery(function ($) {
$("#txtssn").mask("9999");
});
function validateRequest() {
var $form = $('form');
if ($form.valid()) {
$.support.cors = true;
var lnkey = $('#txtlnkey').val();
$.ajax({
type: "GET",
url: "http://localhost:54662/Service1/ValidateRequest/" + encodeURIComponent(lnkey),
contentType: "application/json; charset=utf-8",
dataType: "json", //jsonp?
success: function (response) {
$('#Result').html('Loading....');
if (response.ValidateRequestResult.toString().toUpperCase() == 'TRUE') {
alert('validated');
} else {
alert('cannot validated' + response.ValidateRequestResult.toString().toUpperCase());
//$("#Result").hide();
}
$('#Result').html(response.ValidateRequestResult);
//alert(response.ValidateRequestResult.toString());
},
error: function (errormsg) {
alert("ERROR! \n" + JSON.stringify(errormsg));
}
});
//
} else {
$('#Result').html('Input Validation failed');
}
}
</script>
@using (Html.BeginForm()) {
<fieldset>
<legend>Log in Form</legend>
<ol>
<li>
@Html.LabelFor(m => m.LoanKey, new{})
@Html.TextBoxFor(m => m.LoanKey, new { @id = "txtlnkey" })
@Html.ValidationMessageFor(m => m.LoanKey)
</li>
</ol>
<input type="button" value="Get Status" onclick="javascript:validateRequest();" />
</fieldset>
}
<div id="Result">
@if (ViewBag.Validated)
{
@Html.Action("GetLoanInfo");
}
</div>
下面是我的控制器:
namespace LoanStatus.Web.Controllers
{
public class ValidateController : Controller
{
//
// GET: /Validate/
[HttpGet]
public ActionResult Index()
{
var model = new Validate() {LoanKey = "", Last4Ssn = ""};
ViewBag.Validated = false;
return View(model);
}
[HttpPost]
public ActionResult Index(Validate model, bool validated)
{
// do login stuff
ViewBag.Loankey = model.LoanKey;
ViewBag.Validated = true;
return View(model);
}
public ActionResult GetLoanInfo() // SHOWs Search REsult
{
return PartialView("_LoanInfoPartial", ViewBag.Loankey);
}
}
}
我希望@Html.Action("GetLoanInfo");
只有在 jQuery AJAX 服务调用返回 TRUE 时才呈现“”(我有。我不知道该怎么做。如果我可以将值设置为in alert('validated')
,我的问题可以解决。但根据我读到的内容,它不能在 jQuery 中设置。ViewBag.Validated
success:function()
我试过了$("#Result").hide();
,$("#Result").show();
但没有用。请帮忙。