Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在运行时使用indexeddb中的数据填充cshtml_Javascript_Jquery_.net_View_Indexeddb - Fatal编程技术网

Javascript 在运行时使用indexeddb中的数据填充cshtml

Javascript 在运行时使用indexeddb中的数据填充cshtml,javascript,jquery,.net,view,indexeddb,Javascript,Jquery,.net,View,Indexeddb,我在浏览器中的indexedDB中保存了一个viewmodel,缓存了html页面。示例仅为以下视图的一部分,保存在indexeddb中的模型是InspectionUpsertViewModel: @using Common.OM @using ACA.OM.Tag_M @model ACA.WebERP.Models.Inspection_M.InspectionUpsertViewModel <div class="content"> <div class="blo

我在浏览器中的indexedDB中保存了一个viewmodel,缓存了html页面。示例仅为以下视图的一部分,保存在indexeddb中的模型是InspectionUpsertViewModel:

@using Common.OM
@using ACA.OM.Tag_M
@model ACA.WebERP.Models.Inspection_M.InspectionUpsertViewModel
<div class="content">
    <div class="block block-rounded block-bordered">

        <ul class="nav nav-tabs nav-tabs-alt">
            <li class="nav-item">
                <a id="step1" class="nav-link active" data-toggle="tab" href="#tab-step-1">@ACA.Translations.Measurement.Step1</a>
            </li>
            <li class="nav-item">
                <a class="nav-link disabled" data-toggle="tab" href="#tab-step-2">@ACA.Translations.Measurement.Step2</a>
            </li>
            <li class="nav-item">
                <a id="step3" class="nav-link disabled" data-toggle="tab" href="#tab-step-3">@ACA.Translations.Measurement.Step3</a>
            </li>
        </ul>

        <div class="content">
            <div class="alert alert-danger" role="alert" id="subTypeChangeAlert" style="display:none;">
                @ACA.Translations.Measurement.AlertSubTypeChange
            </div>
            <h4>@ACA.Translations.Inspection.InspectionNr @Model.Inspection.Nr</h4>
        </div>

        @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "step1-form" }))
        {
            @Html.HiddenFor(model => model.Inspection.Id)
            @Html.AntiForgeryToken()

            <div class="tab-pane active" id="tab-step-1" role="tabpanel">
                <div class="block-content">
                    <div class="form-group row">
                        @Html.LabelFor(model => model.Inspection.Article, new { @class = "col-form-label col-md-2" })
                        @Html.HiddenFor(model => model.Inspection.ArticleId)
                        @Html.HiddenFor(model => model.Inspection.Article.AddressId)
                        @Html.HiddenFor(model => model.Inspection.Article.ArticlePropertiesVersion.Id)
                        @Html.HiddenFor(model => model.IsCreatedOnline)
                        @Html.HiddenFor(model => model.QuestionaireId);
                        <div class="col-md-10">
                            <div class="form-group row" id="article" style="@(Model.Inspection.Article != null ? "" : "display: none")">
                                <div class="col-md-10">
                                    <div>
                                        <span class="help-block" id="internNr">@(Model.Inspection.Article != null && !Model.Inspection.Article.InternNr.IsNullOrWhiteSpace() ? $"{ACA.Translations.Article.InternNr}: {Model.Inspection.Article.InternNr}" : "")</span>
                                    </div>
                                    <div>
                                        <span class="help-block" id="serialNr">@(Model.Inspection.Article != null && !Model.Inspection.Article.SerialNr.IsNullOrWhiteSpace() ? $"{ACA.Translations.Article.SerialNr}: {Model.Inspection.Article.SerialNr}" : "")</span>
                                    </div>
                                    <div>
                                        <span class="help-block" id="type">@(Model.Inspection.Article != null ? $"{ACA.Translations.Article.Type}: {Model.Inspection.Article.Type?.Name} - {Model.Inspection.Article.SubType?.Name}" : "")</span>
                                    </div>
                                </div>
                            </div>
                            <div>
                                <button type="button" class="btn btn-warning editArticleButton" data-toggle="modal" data-target="#editArticleModal"><i class="fa fa-pencil-alt"></i></button>
                            </div>
                        </div>
                    </div>
现在我需要在运行时填充数据,所以从indexedDB获取我的对象并在视图中填充对象值。有人知道怎么做吗


提前感谢。

在加载视图之前,将实际模型值加载到控制器操作中是使用Razor语法的唯一方法。因此,为了正确加载值,您只需执行以下操作:

返回视图模型

其中Model是包含数据的对象

为了在视图已经加载的情况下填充这些字段,可以通过Javascript向控制器中的其他操作发出ajax请求,该请求将以以下方式结束:

返回JSONModel

并将返回模型及其数据,然后使用jQuery或任何您想要的工具将其加载到表单中

*编辑*


要比jquery更快地完成此任务,您需要使用实现数据绑定的js库。这类示例是knockout.js和rivets.js,具体取决于最适合您的需要

我已经将返回的JSONModel部分保存在indexeddb中,但是如何使用jquery来填写?我本想使用document.getelementById,但这需要做很多工作。。我只是想知道如何填写这些数据。。该页面需要脱机工作,因此我不能使用任何控制器/ajax请求。@JelledeKeukeleire我编辑了我的答案。请再次检查并批准,因为这是您正在寻找的。