c# - MVC 3 : What's the most common way of asynchronously loading form fields based on previous choices?

标签 c# asp.net-mvc asp.net-mvc-3 razor

想象一下,在一个表单上有两个列表框,第二个列表框的选择取决于第一个列表框的选择。使用 MVC3 解决此问题的最常见或最简洁的方法是什么?

最佳答案

我想说你需要两件事来干净地完成这件事; Ajax 和 Json ActionResult

$('#listbox').change(function() {
  $.ajax({
    url: '/ListBoxChange',
    method: 'POST',
    data: {
      listBoxValue: 'The value'
    },
    success: function(data) {
      alert (data.Result);
    }
  });
});

操作结果:

[HttpPost]
public ActionResult ListBoxChange(string listBoxValue)
{
   string result = GetResult();
   return Json(new {
     Result = result
   });
}

关于c# - MVC 3 : What's the most common way of asynchronously loading form fields based on previous choices?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6673141/

相关文章:

c# - 在 Windows 窗体应用程序表单中嵌入文件资源管理器实例

c# - Unity使用c#翻转纹理

c# - 在自动执行 Controller 中的任何操作之前默认运行方法

c# - 处理传递到 Controller 的模型中的空值

asp.net-mvc - 如何在asp.net mvc中使用表单数据进行重定向?

kendo ui 网格中分页的 Javascript 验证

c# - 在 Eclipse Juno 中使用 Axis 1.1

c# - IFormatProvider 是做什么的?

asp.net-mvc - 从GoDaddy上托管的ASP.NET MVC应用程序发送邮件消息时出现问题

c# - MVC SelectListItem 不实现等于吗?