首页 > 解决方案 > 如何将值从表中的按钮传递到 MVC 中的另一个视图?

问题描述

按下链接按钮时,如何将模型的值从视图传递到另一个视图?

控制器:

public class ViewModel
    {

        public List<DeliverySchedule> ScheduleList { get; set; } 

        public DeliverySchedule ScheduleDetail { get; set; }
    }

public class DeliverySchedule
{
    public int Id { get; set; }
    public string split_date { get; set; }
    public string split_hour { get; set; }
    public string split_qty { get; set; }
    public string remarks { get; set; }
}

public ActionResult Delete(int id)
{
    var model = new ViewModel();

    model.ScheduleDetail = sipContext.OrderDeliverySchedules
                        .Where(o => o.Id == id).SingleOrDefault();                  

    return View(model);
}

看法:

@model Interisland.Areas.v2.Controllers.OrderConfirmationController.ViewModel
@{
    var ScheduleList = Model.ScheduleList;
}

<table id="contentTable" class="table table-hover table-bordered table-sm" style="width:100%">
        <thead>
            <tr class="table-light">
                <th style="width:10%">Delivery Date</th>
                <th style="width:10%">Hour</th>
                <th style="width:10%">Quantity</th>
                <th style="width:60%">Remarks</th>
                <th style="width:10%"></th>
            </tr>
        </thead>
        <tbody>
            @for (int i = 0; i < ScheduleList.Count; i++)
            {
            <tr>
                <td>@ScheduleList[i].split_date</td>
                <td>@ScheduleList[i].split_hour</td>
                <td>@ScheduleList[i].split_qty</td>
                <td>@ScheduleList[i].remarks</td>
                <td>
                    @Url.Action("Edit", "id", new RouteValueDictionary(new { Id = ScheduleList[i].Id }))
                </td>
            </tr>
            }
        </tbody>
    </table>

它一直给我这个错误:

CS0828:无法将方法组分配给匿名类型属性

我的代码有什么问题吗?非常感谢您提供任何帮助

标签: asp.net-mvc

解决方案


尝试这个

  <a href= '@Url.Action("ActionName", "ControllerName", new RouteValueDictionary(new { Id = ScheduleList[i].Id }))'>Edit</a>

推荐阅读