1

我在我的 CRUD 应用程序中使用 jQuery 的 jTable 插件。我的问题是,当我单击更新图标时,更改的值出现在 jtable 中,但在数据库端似乎没有任何改变。我就是想不通....这个问题的根源是什么???这是我的观点的脚本:

@ModelType jTableSampleDatabaseLayer.Hik.JTable.Models.Concour

@Code
ViewData("Title") = "Filtering"
End Code


@section CssImport
<style>
    div.filtering {
        border: 1px solid #999;
        margin-bottom: 5px;
        padding: 10px;
        background-color: #EEE
    }
</style>
 end section

<div class="filtering">
<form>
    <label>Numéro: <input type="text" name="numero" id="numero" />
          <label> Type: @Html.DropDownList("numero_type", DirectCast(ViewBag.types,    IEnumerable(Of SelectListItem)), New With { .id = "numero_type" })
           Nature: @Html.DropDownList("numero_nature", DirectCast(ViewBag.natures, IEnumerable(Of SelectListItem)), New With { .id = "numero_nature" })</label></label>


    <button type = "submit" id="LoadRecordsButton">Rechercher</button>
  </form>
 </div>

 <div id="Tableau" ></div>
    <script >

   $(document).ready(function () {

    //Initialize jTable
    $('#Tableau').jtable({
        title: 'Liste des concours',


        actions: {

            listAction: '@Url.Action("ConcoursListByFiter")',
            deleteAction: '@Url.Action("DeleteConcours")',
            updateAction: '/DefaultPage/UpdateConcours',
            createAction: '@Url.Action("CreateConcours")'
        },

        fields: {
            numero_concours: {
                title: 'numéro',
                width: '21%',
                key: true,
                create: true,
                edit: false,
                columnResizable: true,
                columnSelectable: true
            },     

            numero_type: {
                title: 'type',
                width: '12%',
                options: '@Url.Action("GetTypeOptions")'
            },
            numero_nature: {
                title: 'nature',
                options: '@Url.Action("GetNatureOptions")',
                width: '21%'
            },

            numero_etape: {
                title: 'Etape',
                options: { '1': 'En cours de programmation', '2': 'soumission', '3':      'validé', '4': 'sorti' },
                width: '21%'
            },
            titre_concours: {
                title: 'titre',
                width: '21%'
            },
            date_de_sortie: {
                title: 'date ',
                width: '21%',
                type: 'date',
                displayFormat: 'yy-mm-dd',
                inputClass: 'validate[required,custom[date]]'
            },
            nbre_rangs: {
                title: 'Rang',
                width: '21%'
            },
            nbre_matchs: {
                title: 'Matchs',
                width: '21%'
            }
        }

    });
    //Re-load records when user click 'load records' button.       

    $('#LoadRecordsButton').click(function (e) {
        e.preventDefault();
        $('#Tableau').jtable('load', {
            numero: $('#numero').val(),
            typeId: $('#numero_type').val(),
            natureId: $('#numero_nature').val()

        });
    });

    //Load all records when page is first shown
    $('#LoadRecordsButton').click();



});
  </script>

来自控制器的脚本:

 <HttpPost>
    Public Function UpdateConcours(concours As Concour) As JsonResult
        If (Not (ModelState.IsValid)) Then

            Return Json(New With {Key .Result = "ERROR", Key .Message = "Form is not valid! Please correct it and try again."})
        End If
        Try


            _repository.ConcoursRepository.UpdateConcours(concours)
            Return Json(New With {Key .Result = "OK"})

        Catch ex As Exception

            Return Json(New With {Key .Result = "ERROR", Key .Message = ex.Message})
        End Try
    End Function

以及我的 MemoryConcours Repositroy 中的 UpdateConcours 脚本:

 Public Sub UpdateConcours(concours As Concour) Implements IConcoursRepository.UpdateConcours
        Dim foundConcours As Concour = _dataSource.Concours.FirstOrDefault(Function(s) s.numero_concours = concours.numero_concours)
        If IsNothing(foundConcours) Then

            Return
        End If
        foundConcours.numero_concours = concours.numero_concours
        foundConcours.nbre_matchs = concours.nbre_matchs
        foundConcours.nbre_rangs = concours.nbre_rangs
        foundConcours.numero_etape = concours.numero_etape
        foundConcours.date_de_sortie = concours.date_de_sortie
        foundConcours.numero_type = concours.nbre_rangs
        foundConcours.titre_concours = concours.titre_concours
        foundConcours.numero_nature = concours.numero_nature
        Dim e As Concour = (From o In x.Concours Where o.numero_concours = concours.numero_concours Select o).First()
        x.Entry(e).OriginalValues().SetValues(concours)
        x.ChangeTracker.DetectChanges()
        x.SaveChanges()



    End Sub

ps:虽然更新没有错误消息,只是值在表上更新,而不是在数据库端!

4

0 回答 0