option based view.

  public async Task<ActionResult> Create()

        {

            LoanClientMaster loanClientMaster = new LoanClientMaster();

            await InitCommonAsync(loanClientMaster);

            return View();

        }


        // POST: LoanClientMasters/Create

        // To protect from overposting attacks, enable the specific properties you want to bind to, for

        // more details see https://go.microsoft.com/fwlink/?LinkId=317598.

        [HttpPost]

        //[ValidateAntiForgeryToken]

        public async Task<ActionResult> Create(LoanClientMaster loanClientMaster, int LoanBorrowerTypeID, LoanIndvidualClientFileUpload[] loanIndvidualClientFileUploads, LoanInstitutionalClientFileUpload[] loanInstitutionalClientFileUploads)

        {

            try

            {

                ModelState.Clear();

                TryValidateModel(loanClientMaster);

                if (ModelState.IsValid)

                {

                    if (LoanBorrowerTypeID == (int)EnumBorrowerType.Individual)

                    {

                        await _clientService._IndividualClientAsync(loanClientMaster, LoanBorrowerTypeID, loanIndvidualClientFileUploads);

                        FlashBag.setMessage(true, "Successfully Saved Client Individual Information!");

                    }

                    else if (LoanBorrowerTypeID == (int)EnumBorrowerType.Institutional)

                    {

                        await _clientService._InstutionalClientAsync(loanClientMaster, LoanBorrowerTypeID, loanInstitutionalClientFileUploads);

                        FlashBag.setMessage(true, "Successfully Saved Client Instutional Information!");

                    }

                }

            }

            catch (DbEntityValidationException e)

            {

                StringBuilder sb = new StringBuilder();

                foreach (var eve in e.EntityValidationErrors)

                {

                    sb.AppendFormat("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",

                        eve.Entry.Entity.GetType().Name, eve.Entry.State);

                    foreach (var ve in eve.ValidationErrors)

                    {

                        sb.AppendFormat("- Property: \"{0}\", Error: \"{1}\"",

                            ve.PropertyName, ve.ErrorMessage);

                    }

                }

                ModelState.AddModelError("", sb.ToString());

            }

            catch (Exception ex)

            {

                FlashBag.setMessage(false, ex.Message);

            }

            return RedirectToAction("Index");

        }

---------------------------------

view


@model WorkFlow.Infrastructure.Model.LoanClientMaster


@{

    ViewBag.Title = "Create";

}


<div class="container">

    <div class="toolbar row">

        <div class="col-sm-6 hidden-xs">

            <div class="page-header">

                <h1 class="">

                    Client

                    <small>Create</small>

                </h1>

            </div>

        </div>

        <div class="col-sm-6 col-xs-12">

            <div class="toolbar-tools pull-right">

                <ul class="nav navbar-right">

                    <li class="back">

                        <a href="@Url.Action("Index")">

                            <i class="fa fa-chevron-left"></i>Back

                        </a>

                    </li>

                </ul>

            </div>

        </div>

    </div>

    <div class="row">

        <div class="col-md-12">

            <div class="form-horizontal">

                <div class="panel panel-default">

                    <div class="panel-body">

                        @*@Html.AntiForgeryToken()*@

                        @using (Html.BeginForm("Create", "LoanClientMasters", FormMethod.Post, new { enctype = "multipart/form-data" }))

                        {

                            <div class="row form-group">

                                <label class="control-label col-md-2">Borrower Type*</label>

                                <div class="col-md-4">

                                    @Html.DropDownList("BorrowerList", null, htmlAttributes: new { @class = "form-control search-select", @Name = "LoanBorrowerTypeID" })

                                </div>

                                @Html.LabelFor(model => model.ClientCode, htmlAttributes: new { @class = "control-label col-md-2" })

                                <div class="col-md-4">

                                    @Html.EditorFor(model => model.ClientCode, new { htmlAttributes = new { @class = "form-control" } })

                                    @Html.ValidationMessageFor(model => model.ClientCode, "", new { @class = "text-danger" })

                                </div>

                            </div>

                            <div class="Businesstype">

                                <div class="individual">

                                    @Html.Partial("partial/_LoanIndividual")

                                </div>

                                <div class="instutional">

                                    @Html.Partial("partial/_LoanInstitutional")

                                </div>

                                <br />


                                <input type="hidden" id="ContactNumber" name="ContactNumber" />

                                <input type="hidden" id="PANNumber" name="PANNumber" />

                                @*<div class="row form-group" style="display:block;">*@

                                @*<div class="row form-group" style="display:none;">

                                        @Html.LabelFor(model => model.ContactNumber, htmlAttributes: new { @class = "control-label col-md-2" })

                                        <div class="col-md-4">

                                            @Html.EditorFor(model => model.ContactNumber, new { htmlAttributes = new { @class = "form-control" } })

                                            @Html.ValidationMessageFor(model => model.ContactNumber, "", new { @class = "text-danger" })

                                        </div>


                                        @Html.LabelFor(model => model.PANNumber, htmlAttributes: new { @class = "control-label col-md-2" })

                                        <div class="col-md-4">

                                            @Html.EditorFor(model => model.PANNumber, new { htmlAttributes = new { @class = "form-control" } })

                                            @Html.ValidationMessageFor(model => model.PANNumber, "", new { @class = "text-danger" })

                                        </div>

                                    </div>*@

                            </div>

                            <div class="row form-group">

                                <div class="col-md-2 col-md-offset-10">

                                    <input type="submit" value="Save" class="btn btn-success " />

                                </div>

                            </div>

                        }

                    </div>

                </div>

            </div>

        </div>

    </div>


</div>

@section Scripts {

    @Scripts.Render("~/bundles/jqueryval")


    <script src= '@Url.Content("~/Scripts/LoanMasterClient/ClientScript.js")'></script>

}

-----------------------------------------------
-------------------------------------------------


$(document).ready(function () {
    //dynAddRow('#individualtbl');
    //  console.log("is=" +    $('#BorrowerType').val());

    $('.btn').show();
    $('.Businesstype').show();
    $('.individual').show();
    $('.instutional').hide();
    $('#BorrowerList').on('change', function () {
        var id = $('#BorrowerList').val();
        //BusinessTypeAppend(id);
        isindivisual(id);
        // console.log("div=" + id);
    })/*.trigger('change')*/;
    $("#txtContactNumber").on("keyup", function () {
        $("#ContactNumber").val($("#txtContactNumber").val());
    })
    $("#txtPAN").on("keyup", function () {
        $("#PANNumber").val($("#txtPAN").val());
    })
    $("#txtInsPAN").on("keyup", function () {
        $("#PANNumber").val($("#txtInsPAN").val());
    })
    $("#txtInsContactNumber").on("keyup", function () {
        $("#ContactNumber").val($("#txtInsContactNumber").val());
    })
});
function isindivisual(id) {
    if (id == 1) {
        $('.Businesstype').show();
        $('.individual').show();
        $('.instutional').hide();
        $('.btn').show();
    }
    else if (id == 2) {
        $('.Businesstype').show();
        $('.instutional').show();
        $('.individual').hide();
        $('.btn').show();
    }
    else if (id == "") {
        $('.Businesstype').hide();
        $('.btn').hide();
    }
}


Comments