基于MVC中的下拉选择重新加载视图

问题描述

我需要找到一种方法显示所选下拉值的数据。到目前为止,代码是这样的 - 认寄存器 X 的数据将在页面加载时显示在“索引”视图中,从下拉列表中选择新寄存器后,需要在同一“索引”视图中替换寄存器 Y 数据。 当我调试代码时,我能够看到在 display() 下的 ViewList 中填充的新数据,但同样没有传输到主视图。此外,@Model.store、@Model.reg 值不会选择从控制器 RedirectToAction 分配的新值。 请建议一种使用所选寄存器的信息重新填充视图的方法

控制器

public class AppHealthController : Controller
    {
        dynamic ViewList = new ExpandoObject();
        public ActionResult Index()
        {   
            ViewList.store = "0100";
            ViewList.reg = "001";
            ViewList.RegList = GetAllRegisterList(A,B);
            ViewList.RegInfo = ReadAPIinfo(C,D);
            return View("Index",ViewList);              
         }

        [HttpPost]
        public ActionResult display(string selectRegister)
        {
            ViewList.store = "0001";
            ViewList.reg = selectRegister.Substring(8,3);
            ViewList.RegInfo = ReadAPIinfo(C,selectRegister);
            return RedirectToAction("Index",ViewList);
        }
} 

查看

@model dynamic 
 @{ViewBag.Title = "Index";}
    <script>
        $("body").on("change","#selectRegister",function () {
            $("#selectRegister").val($(this).find("option:selected").text());
        });
    </script>  


    
    <body>
        <table style="width:100%" class="table1">
            <tr>
                <td><b>StoreNumber :</b>@Model.store</td>
                <td><b>RegisterNumber :</b>@Model.reg</td>
                <td>
                    <b>Register List</b>
                    @using (Html.BeginForm("display","AppHealth",FormMethod.Post))
                    {
                        <select id="selectRegister" name="selectRegister" onchange="this.form.submit();">
                            @foreach (RegisterList item in Model.RegList.Result)
                            {
                            <option>@Html.displayFor(x => @item.RegisterNo)</option>
                            }
                        </select>
                    }
                </td>
            </tr>
        </table>
    
    <table id="'tblHealth"><tbody>Model.RegInfo.Result[0]</tbody></table> 

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)