RAZOR从下拉列表中调用控制器方法 [英] RAZOR call a controller method from the dropdownlist

查看:110
本文介绍了RAZOR从下拉列表中调用控制器方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的编程社区,



我试图通过从控制器调用方法来填充下拉列表。

之所以如此我这样做是因为我想传递一个id,因此每个记录都会得到一个不同的列表。



查看



Dear programming community,

I am trying to populate the dropdown list by calling a method from the controller.
The reason why i am doing this is because i want to pass it an id and therefore ill be getting a different list for each record.

View

grid.Column(header: "Wards", format: @<text>@Html.DropDownList(@Url.Action("getDoctorsWards", "Doctor", new { id = 1 }), "Ward_id")</text>)









控制器







Controller

public ViewResult getDoctorsWards(int id)
        {
            var myModel = db.Wards.Where(a => a.Doctor.Doctor_id == id).ToList();
            return View(myModel);
        }







欢迎任何意见或建议。




Any comments or suggestions are welcome.

推荐答案

您必须从控制器返回JSON格式的结果。然后在客户端使用JQuery使用JSON结果集填充下拉列表中的值。
You have to return the result in JSON format from controller. Then at the client side use JQuery to populate the values in the dropdown list using the JSON resultset.


这篇关于RAZOR从下拉列表中调用控制器方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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