1

ローン番号を入力できるページが必要な場合は、WCF get サービスを呼び出して、ローン番号が有効かどうかを確認します。ローン番号が有効な場合、同じページにローン関連のデータ (部分ビュー) を表示したい。

これが私の主なビューです:

@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.Validatedsuccess:function()

試し$("#Result").hide();てみ$("#Result").show();ましたが、うまくいきませんでした。助けてください。

4

1 に答える 1

2

これで試すことができますか:

関数 validateRequest() ajax の成功で、alert('validated'); を表示している場所で これを使用して試してください:

$('#Result').load('@Url.Action("GetLoanInfo", "Validate")');

ビューで Result div を空にします

<div id="Result"> </div>

それが役立つかどうか教えてください。

于 2013-04-20T04:44:05.353 に答える