asp.net-mvc - 如何将值从表中的按钮传递到 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:无法将方法组分配给匿名类型属性
我的代码有什么问题吗?非常感谢您提供任何帮助
解决方案
尝试这个
<a href= '@Url.Action("ActionName", "ControllerName", new RouteValueDictionary(new { Id = ScheduleList[i].Id }))'>Edit</a>
推荐阅读
- tensorflow - GradientTape 计算损失函数中的显着性
- c - 删除链表中的第一个节点或弹出队列
- angular - Angular中的绘图仅呈现第一个接收到的值
- swift - 如何将 SwiftUI 视图绑定到数组中元素的属性
- node.js - webpack 节点 API 中的观看模式
- r - 使用向量化将矩阵与 R 中的向量进行逐行比较
- algorithm - 这个程序的复杂性是 n^2*logn 还是什么?
- html - 如何将表单元素移动到中心?
- java - 如何从名字中取出 3 个随机字母,从姓氏和电话号码中取出 2 个字母,从给定字符串“specialChar”中取出 1 个符号
- node.js - 如何使用带有 mongodb 的 nodejs 更新数组中的嵌套对象?