jquery $ .post MVC控制器使用模型返回刷新相同的视图

时间:2016-12-30 17:50:50

标签: c# jquery razor model-view-controller http-post

我需要帮助。 我有一个mvc视图,双击一个mvc控制器调用并传递选定的tr数据

    var f = $('#frmUtente');
    var action = f.attr('action');
    var lvm = []
    lvm.push({ name: 'JsonResponse', value: JSON.stringify(data) })
    $.post(action, lvm)
        .done(function (data) {
            $("#divResult").hide();
            showRicerca();
        })
        .fail(function () {
            $('.alert-danger', $('.login-form')).show();
            $('#loader-wrapper').hide();
        });

我的mvc控制器序列化json结果并转换成模型视图,调用相同视图后的vith模型

    [HttpPost]
    public ActionResult UtenteEdit(string JsonResponse)
    {
        //recupero credenziali
        UtenteModelView umv = Newtonsoft.Json.JsonConvert.DeserializeObject<UtenteModelView>(JsonResponse);
        umv.ModeView = UtenteModelView.MODEVIEW.EDIT;

        return View("~/Views/Home/Create.cshtml", umv);
    }

我的观点是

@using ErpLibrary.dao;
@using ErpMvc.Models;

@model ErpMvc.Models.UtenteModelView

@Html.Partial("~/Views/Shared/_BasePage.cshtml")

@{
    ViewBag.Title = "Utenti";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section css{
    <link href="~/Template/global/plugins/datatables/datatables.min.css" rel="stylesheet" type="text/css" />
    <link href="~/Template/global/plugins/datatables/plugins/editor/css/editor.dataTables.min.css" rel="stylesheet" type="text/css" />
}

@Html.HiddenFor(m => m.ModeView, new { @id = "hMODEVIEW" })
<div class="page-content">
    <div class="row">
        <div class="col-md-12">
            <div class="portlet box blue" style="border-right: 1px !important;border-bottom: 0px !important;">
                <div class="portlet-title tabbable-line ">
                    <div class="caption caption-md">
                        <i class="icon-globe theme-font hide"></i>
                        <span class="caption-subject" style="font-size: 24px !important;font-weight: 100 !important;">
                            Utenti&nbsp;
                            <i class="fa fa-spinner fa-spin fa-fw" id="loadUtenti"></i>
                            <a href="#" title="CTRL+F" id="aSearch"><i class="fa fa-search" aria-hidden="true" style="color: black;"></i></a>
                        </span>
                    </div>
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a href="#tab_1_1" data-toggle="tab">Informazioni</a>
                        </li>
                        <li>
                            <a href="#tab_1_3" data-toggle="tab">Password</a>
                        </li>
                        <li>
                            <a href="#tab_1_2" data-toggle="tab">Avatar</a>
                        </li>

                    </ul>
                    <div class="line-bottom" style="border-top: 1px solid #e7ecf1 !important;margin-top: 60px;"></div>
                    <div class="alert alert-danger display-hide">
                        <button class="close" data-close="alert"></button>
                        <span> Errore: alcuni campi obbligatori non sono stati valorizzati</span>
                    </div>
                    <!--START RICERCA-->
                    <div class="portlet-body form" style="border:solid 1px #e7ecf1;border-top:none;padding: 15px 15px 15px 15px;display:none" id="divSearch">
                        <form role="form" action="#" id="frmSearch" name="frmSearch" class="search">
                            <div class="form-body">
                                <div class="row">
                                    <div class="col-md-4"><div class="form-group"><input type="text" placeholder="Utente" class="form-control focus" id="pUserid" name="pUserid" /></div></div>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            @{
                                                _Select2View ps2vStato = new _Select2View();
                                                ps2vStato.IdSelect = "pState";
                                                ps2vStato.TypeSelect = TYPE.STATO;
                                                ps2vStato.PlaceHolder = "Stato";
                                            }
                                            @Html.Partial("~/Views/Shared/_Select2.cshtml", ps2vStato)
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            @{
                                                _Select2View ps2vRole = new _Select2View();
                                                ps2vRole.IdSelect = "pRole";
                                                ps2vRole.TypeSelect = TYPE.RUOLO;
                                                ps2vRole.PlaceHolder = "Ruolo";
                                            }
                                            @Html.Partial("~/Views/Shared/_Select2.cshtml", ps2vRole)
                                        </div>
                                    </div>
                                </div>
                                <div class="form-actions right ">
                                    <button type="button" class="btn default" id="btnAnnullaSearch">Annulla</button> @*Chiude la form di ricerca*@
                                    <button type="button" id="btnSearch" class="btn blue"> Cerca </button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <!--END RICERCA-->
                    <!--START RESULT-->
                    <div class="portlet-body form" id="divResult" style="border:solid 1px #e7ecf1;border-top:none;padding:15px;display:none">
                        <form role="form" action="#" id="frmResult" name="fmrResult">
                            <div class="row">
                                <div class="col-md-12">
                                    <table class="display" cellspacing="0" width="100%" id="tableUtenti">
                                        <tbody>
                                            <tr><td class="dataTables_empty" colspan="5">Nessun risultato</td></tr>
                                        </tbody>
                                    </table>
                                    @{
                                        _DataTable pw = new _DataTable();
                                        pw.idTable = "tableUtenti";
                                        pw.idSpinner = "loadUtenti";
                                        pw.idLoader = "loader-wrapper";
                                        pw.idSrc = "id";
                                        //add option
                                        pw.options.Add("filter", "false");
                                        pw.options.Add("info", "false");
                                        pw.options.Add("ordering", "false");
                                        pw.options.Add("processing", "true");
                                        pw.options.Add("retrieve", "true");
                                        //add columns DataTables
                                        pw.lsColumn.Add(new Column { Name = "Id", Title = "Identificativo", Orderable = "true", ClassName = "dt-center", Visible = true });
                                        pw.lsColumn.Add(new Column { Name = "Userid", Title = "Utente", Orderable = "true", ClassName = "dt-left", Visible = true });
                                        pw.lsColumn.Add(new Column { Name = "State.text", Title = "Stato", Orderable = "true", ClassName = "dt-left", Visible = true });
                                        pw.lsColumn.Add(new Column { Name = "Role.text", Title = "Ruolo", Orderable = "true", ClassName = "dt-left", Visible = true });
                                        pw.lsColumn.Add(new Column { Name = "TsPwd", Title = "Ts. Psw", Orderable = "true", ClassName = "dt-left", Type = TYPEFIELD.DATETIME, Visible = false });
                                        pw.lsColumn.Add(new Column { Name = "TsState", Title = "Ts. State", Orderable = "true", ClassName = "dt-left", Type = TYPEFIELD.DATETIME, Visible = true });
                                        //add Fields Editor
                                        //CallBack definition
                                        pw.callBackEditForm = "EditUtente";
                                    }
                                    @Html.Partial("~/Views/Shared/_DataTable.cshtml", pw)
                                </div>
                            </div>
                        </form>
                    </div>
                    <!--END RESULT-->
                </div>
                <div class="portlet-body form">
                    <form role="form" action="~/Home/UtenteEdit" id="frmUtente" name="frmUtente">
                        <div class="form-body">
                            <div class="tab-content">
                                <!-- PERSONAL INFO TAB -->
                                <div class="tab-pane active" id="tab_1_1">
                                    <div class="row">
                                        <div class="col-md-2">
                                            <div class="form-group">
                                                <label class="control-label sr-only">Id</label>
                                                @*<input type="text" placeholder="Identificativo" class="form-control" readonly id="Id"/>*@
                                                @Html.TextBoxFor(m => m.Id, new { @placeholder = "Identificativo", @class = "form-control", @id = "Id", @readonly = "readonly" })
                                            </div>
                                        </div>
                                        <div class="col-md-10">
                                            <div class="form-group">
                                                <label class="control-label sr-only">User</label>
                                                @*<input type="text" placeholder="Utente" class="form-control focus" required maxlength="25" id="Userid" name="Userid"/>*@
                                                @Html.TextBoxFor(m => m.Userid, new { @placeholder = "Utente", @class = "form-control focus", @id = "Userid", @name = "Userid", @maxlength = "25", @required = "required" })
                                            </div>
                                        </div>

                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="control-label sr-only">Stato</label>
                                                @{
                                                    _Select2View s2vStato = new _Select2View();
                                                    s2vStato.IdSelect = "IdState";
                                                    s2vStato.TypeSelect = TYPE.STATO;
                                                    s2vStato.PlaceHolder = "Stato";
                                                    s2vStato.MinimumInputLength = 0;
                                                    if (Model != null) { s2vStato.Selected = Model.IdState.ToString(); }
                                                }
                                                @Html.Partial("~/Views/Shared/_Select2.cshtml", s2vStato)
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="control-label sr-only">Ruolo</label>
                                                @{
                                                    _Select2View s2vRole = new _Select2View();
                                                    s2vRole.IdSelect = "IdRole";
                                                    s2vRole.TypeSelect = TYPE.RUOLO;
                                                    s2vRole.PlaceHolder = "Ruolo";
                                                    s2vRole.MinimumInputLength = 0;
                                                    if (Model != null) { s2vStato.Selected = Model.IdRole.ToString(); }
                                                }
                                                @Html.Partial("~/Views/Shared/_Select2.cshtml", s2vRole)
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- END PERSONAL INFO TAB -->
                                <!-- CHANGE AVATAR TAB -->
                                <div class="tab-pane" id="tab_1_2">
                                    <p>
                                        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum
                                        eiusmod.
                                    </p>
                                    <div class="form-group">
                                        <div class="fileinput fileinput-new" data-provides="fileinput">
                                            <div class="fileinput-new thumbnail" style="width: 200px; height: 150px;">
                                                <img src="http://www.placehold.it/200x150/EFEFEF/AAAAAA&amp;text=no+image" alt="" />
                                            </div>
                                            <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"> </div>
                                            <div>
                                                <span class="btn default btn-file">
                                                    <span class="fileinput-new"> Select image </span>
                                                    <span class="fileinput-exists"> Change </span>
                                                    <input type="file" name="...">
                                                </span>
                                                <a href="javascript:;" class="btn default fileinput-exists" data-dismiss="fileinput"> Remove </a>
                                            </div>
                                        </div>
                                        <div class="clearfix margin-top-10">
                                            <span class="label label-danger">NOTE! </span>
                                            <span>Attached image thumbnail is supported in Latest Firefox, Chrome, Opera, Safari and Internet Explorer 10 only </span>
                                        </div>
                                    </div>
                                    <div class="margin-top-10">
                                        <a href="javascript:;" class="btn green"> Submit </a>
                                        <a href="javascript:;" class="btn default"> Cancel </a>
                                    </div>
                                </div>
                                <!-- END CHANGE AVATAR TAB -->
                                <!-- CHANGE PASSWORD TAB -->
                                <div class="tab-pane" id="tab_1_3">
                                    @{
                                        if (Model == null || Model.ModeView == UtenteModelView.MODEVIEW.NEW)
                                        {
                                            <div class="form-group">
                                                <label class="control-label sr-only">Current Password</label>
                                                @*<input type="password" class="form-control" placeholder="Password" id="Psw" name="Psw" />*@
                                                @Html.TextBoxFor(m => m.Psw, new { @type = "password", @class = "form-control", @placeholder = "Password", @id = "Psw", @name = "Psw" })
                                            </div>
                                        }
                                        else
                                        {
                                            <div class="form-group">
                                                <label class="control-label sr-only">Current Password</label>
                                                @*<input type="password" class="form-control" placeholder="Password Corrente" id="Psw" name="Psw"/>*@
                                                @Html.TextBoxFor(m => m.Psw, new { @type = "password", @class = "form-control", @placeholder = "Password Corrente", @id = "Psw", @name = "Psw" })
                                            </div>
                                            <div class="form-group">
                                                <label class="control-label sr-only">New Password</label>
                                                @*<input type="password" class="form-control" placeholder="Nuova Password" id="PswNew" name="PswNew" />*@
                                                @Html.TextBoxFor(m => m.Psw, new { @type = "password", @class = "form-control", @placeholder = "Nuova Password", @id = "PswNew", @name = "PswNew" })


                                            </div>
                                            <div class="form-group">
                                                <label class="control-label sr-only">Re-type New Password</label>
                                                @*<input type="password" class="form-control" placeholder="Conferma Password" id="PswNewConfirm" name="PswNewConfirm" />*@
                                                @Html.TextBoxFor(m => m.Psw, new { @type = "password", @class = "form-control", @placeholder = "Conferma Password", @id = "PswNewConfirm", @name = "PswNewConfirm" })
                                            </div>
                                        }
                                    }
                                    @*<div class="margin-top-10">
                                            <a href="javascript:;" class="btn green"> Change Password </a>
                                            <a href="javascript:;" class="btn default"> Cancel </a>
                                        </div>*@
                                </div>
                                <!-- END CHANGE PASSWORD TAB -->
                            </div>
                            <div class="form-actions right">
                                <button type="button" class="btn default" id="btnAnnulla">Annulla</button>
                                <button type="button" id="btnSave" class="btn blue">
                                    <i class="fa fa-check"></i> Salva
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

我的问题是视图不刷新数据模型

任何想法

感谢

0 个答案:

没有答案