English 中文(简体)
MVC3 文本框文本文本更改事件
原标题:MVC3 Text Box Text change Event

我使用 mvc3 有以下情景:

我有一个数据库表格, 包含一个记录ID、 记录Name 和记录类型。 显示为三个文本框, 每个前述字段都显示一个 。

我的问题是,当我在相关文本框中输入音频ID时,我想能够显示该特定音频ID的录音Name和音频Type。我如何才能做到这一点?

最佳回答

视图 :

@Html.TextBoxFor(model => model.RecordId)
@Html.TextBoxFor(model => model.RecordName)
@Html.TextBoxFor(model => model.RecordType)

<script language="javascript">
$( #RecordId ).change(function(){
    var recordId = this.value;
    $.getJSON("/MyController/GetRecordById",
        {
            id: recordId
        },
        function (data) {
            $( RecordName ).val(data.Name);
            $( RecordType ).val(data.Type);
        });
});
</script>

主计长:

public JsonResult GetRecordById(int id)
{
    var record = recordRepository.GetById(id);
    var result = new {
                         Name = record.Name,
                         Type = record.Type
                     }

    return Json(result, JsonRequestBehavior.AllowGet);
}
问题回答

暂无回答




相关问题
Using jquery to get a partial view and updating the UI

I need to render a partial view (returned from the controller) to show some customer summary details. This will need to happen when the user clicks on a button. In the the mean time the user can ...

MVC 2 / MVC 3 / MVC 4

MVC 2 我们可以轻松地创造领域。 现在,我的问题涉及nes地区(地区内)。

Asp.Net MVC 2 - Changing the PropertyValueRequired string

Using a resx file in the App_GlobalResources directory, I ve been able to change the default message for the PropertyValueInvalid string of the model validators. But it doesn t work to translate the ...

ASP.NET MVC 3 - What features do you want to see? [closed]

I know a bunch of people that are really enjoying the improvements that ASP.NET MVC 2 made over the first release. I have just started to migrate our MVC 1 project over and so far areas has totally ...

热门标签