2

这是一个 MVC VB.NET Razor 应用程序。我有一个加载在父视图底部的部分视图。在那个局部视图中,我有一些按钮,当单击时会触发一个弹出对话框模式窗口,该窗口附加了一个局部视图。用户应该能够编辑表单,然后单击更新,然后将信息发布到控制器。但是,我在提交时收到以下错误消息。

在此处输入图像描述

我关注了这里的博客来把所有东西都连接起来。单击更新按钮时,此处出现错误:

在此处输入图像描述

下面是包含触发弹出模式的按钮和 javascript 的 PartialView

@ModelTYPE IEnumerable(of data_manager.attendance)

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascrip</script>
<table>
<tr>
    <th>Conf. Number</th>
    <th>Class Title</th>
    <th>Status of Class</th>
    <td>Edit</td>
</tr>    
@For Each x In Model
    Dim currentItem = x
    @<tr>
    <td>@Html.DisplayFor(Function(f) currentItem.conf_number)</td>
    <td>@Html.DisplayFor(Function(f) currentItem.courseTitle)</td>
    @If currentItem.Completed_Class = "Completed" Then
        @<td>@Html.ActionLink("Completed(Print Cert)", "Ind_Cert", "Printing", New With {.firstName = currentItem.firstName, .lastname = currentItem.lastName, .classRef = currentItem.course_ref, .cNumber = currentItem.conf_number}, Nothing)</td>
    Else
        @<td>@Html.DisplayFor(Function(f) currentItem.Completed_Class)</td> 
    End If
    <td>@Html.ActionLink("Modify", "CourseHistoryEdit", New With {.id = currentItem.id}, New With {.class = "editLink"})</td>
    </tr>
Next
</table>
<div id="updateDialog" title="Update Attendance"></div>

<script type="text/javascript">
var linkObj;
$(function () {
    $(".editLink").button();
    $('#updateDialog').dialog({
        autoOpen: false,
        width: 400,
        resizable: false,
        modal: true,
        buttons: {
            "Update": function () {
                $("#update-message").html(''); //make sure there is nothing on the message before we continue                         
                $("#updateAttendance").submit();
            },
            "Cancel": function () {
                $(this).dialog("close");
            }
        }
    });
    $(".editLink").click(function () {
        //change the title of the dialgo
        linkObj = $(this);
        var dialogDiv = $('#updateDialog');
        var viewUrl = linkObj.attr('href');
        $.get(viewUrl, function (data) {
            dialogDiv.html(data);
            //validation
            var $form = $("#updateAttendance");
            // Unbind existing validation
            $form.unbind();
            $form.data("validator", null);
            // Check document for changes
            $.validator.unobtrusive.parse(document);
            // Re add validation with changes
            $form.validate($form.data("unobtrusiveValidation").options);
            //open dialog
            dialogDiv.dialog('open');
        });
        return false;
    });
});

function updateSuccess(data) {
    if (data.Success == true) {
        //we update the table's info
        var parent = linkObj.closest("tr");
        parent.find(".Completed_Class").html(data.Object.completed);
        parent.find(".carDescription").html(data.Object.Description);
        //now we can close the dialog
        $('#updateDialog').dialog('close');
        //twitter type notification
        $('#commonMessage').html("Update Complete");
        $('#commonMessage').delay(400).slideDown(400).delay(3000).slideUp(400);
    }
    else {
        $("#update-message").html(data.ErrorMessage);
        $("#update-message").show();
    }
}
</script>

这是在单击每个旁边的 Modify 按钮时呈现的 partialView。

   @ModelTYPE DataModels.DataModels.AjaxCourseHistoryEdit

   @Using (Ajax.BeginForm("CourseHistoryEdit", "Admin", Nothing, New AjaxOptions With {.InsertionMode = InsertionMode.Replace, .HttpMethod = "POST", .OnSuccess = "updateSuccess"}, New With {.id = "updateAttendance"}))
   @Html.ValidationSummary(true)

   @<fieldset>
   <legend>Attendance Update</legend>
   @Html.HiddenFor(Function(m) Model.attendId) 
   <div class="editor-label">
    @Html.Label("Course Title")
   </div>
   <div class="editor-field">
    @Html.DisplayFor(Function(m) Model.courseTitle)
   </div>
   <div class="editor-label">
    @Html.Label("Completed Status")
   </div>
   <div class="editor-field">
     @Html.DropDownList("completed", New SelectList(ViewBag.CourseStatuses))
   </div>
   <div class="editor-label">
    @Html.Label("Hours Completed")
   </div>
   <div>
    @Html.EditorFor(Function(m) Model.hoursCompleted)
   </div>
   </fieldset>    
   End Using

下面是在项目的 _layout 文件中加载的 javascript 库。

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript">     </script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

任何帮助是极大的赞赏。我已经解决了几个小时,谷歌搜索出现了几个 SO 帖子,说这Unexpected token u与无效的线路终止有关。这对我没有帮助,因为我找不到任何看起来像不正确的 html 的东西,即未关闭的标签。

我有一个 csharper 提出了@关于 table 和 fieldset 的问题。在 vb.net 的这些实例中这是正常的,下面是呈现的 html 的屏幕截图 在此处输入图像描述

4

1 回答 1

2

A comment made by Moeri pointed me in the right direction. It turned out that my model was using a integer value for the hiddenFor value. Which for reasons unknown to me the AJAX post did not like that at all. By changing the type of attendId from Integer to String and further using proper editorFor / labelFor the issue has been resolved. Maybe this will help someone that hits this stumbling block as I have.

于 2013-09-07T02:09:40.117 回答