DDL失败AJAX中更改来电MVC [英] DDL fails to change during AJAX call MVC

查看:166
本文介绍了DDL失败AJAX中更改来电MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Ajax调用期间要改变位置的值,从而节省了用户的时间上的改变手工的价值,我已经尝试过,但显然不工作(请参见下面的code)在那里我去错了什么想法?

i want the value of location to be changed during the ajax call, thus saving the user time on altering the value by hand, i've attempted it but clearly doesn't work (see the code below), any ideas on where im going wrong?

_CameraInfo.cshtml(局部视图)

_CameraInfo.cshtml (partial view)

@model JobTracker.Models.Job


<h2>Edit and Confirm</h2>

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)

<fieldset>
    <legend>Job</legend>

    @Html.HiddenFor(model => model.JobID)

    @Html.HiddenFor(model => model.OrderID)

  <div class="editor-label">
        @Html.LabelFor(model => model.LocationID, "Location")
    </div>
    <div class="editor-field">
        @Html.DropDownList("LocationID", null, new {id ="Location" })
        @Html.ValidationMessageFor(model => model.LocationID)
    </div><br />

    <div class="editor-label">
        @Html.LabelFor(model => model.HighPriority)
    </div>
    <div class="editor-field">
        @Html.DropDownListFor(model => model.HighPriority, new SelectList(
    new[] 
    { 
        new { Value = "Yes", Text = "Yes" },
        new { Value = "No", Text = "No" },
    },
     "Value",
     "Text",
    Model
))

        @Html.ValidationMessageFor(model => model.HighPriority)
    </div><br />

    <div class="editor-label">
        @Html.LabelFor(model => model.Comments)
    </div>
    <div class="editor-field">
        @Html.TextAreaFor(model => model.Comments)
        @Html.ValidationMessageFor(model => model.Comments)
    </div><br />

      <div class="editor-label">
        @Html.LabelFor(model => model.Status)
    </div>
    <div class="editor-field">
           @Html.DropDownListFor(model => model.Status, new SelectList(
    new[] 
    { 
        new { Value = "In Progress", Text = "In Progress" },
        new { Value = "Completed", Text = "Completed" },
        new { Value = "Not Started", Text = "Not Started" },
        new { Value = "Stopped", Text = "Stopped" },
    },
     "Value",
     "Text",
    Model
))
        @Html.ValidationMessageFor(model => model.Status)
    </div><br />

    <p>
        <input type="submit" value="Save" />
    </p>
</fieldset>

}

AJAX调用

AJAX call

     $(document).ready(function () {
    $('#qr-number').on('change', function () {
        var ddl = $('#Location');
        var value = "cleanroom";
        $.ajax({
            type: "Get",
            url: '/CameraInfo/Edit',
            data: { ID: $('#qr-number').val() },
            success: function (response) {
                ddl.val(value);
                $('#Sample').html(response);
            },
            error: function (response) {
                if (response.responseText != "") {
                    alert(response.responseText);
                    alert("Some thing wrong..");
                }
            }
        });
    });
    });
});

该DDL填充的模型数据的方式。

The DDL is populated by the model data by the way.

我presume它没有成功出于某种原因在改变,也许是因为认为心不是满载?

I presume it doesnt alter during the success for some reason, maybe it because the view isnt fully loaded?

请让我们,如果你需要任何进一步的信息,我知道了:)

Please let me know if you require any further information :)

推荐答案

几件事情来检查。确保在呈现下拉的id是位置。有些佣工将覆盖变化。下一步要确保你有你的下拉菜单中的选项有值=净室。如果你想通过文字来设置见<一href="http://stackoverflow.com/questions/1888931/set-dropdown-value-by-text-using-jquery">Here

couple things to check. make sure the id on the rendered drop down is Location. Some of the helpers will override that change. Next make sure that you have an option in your dropdown that has value="cleanroom". if you are trying to set by text see Here

这篇关于DDL失败AJAX中更改来电MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆