[英]Using mvc2 and c#, how do I call a void method in my controller from view
[英]How do I call another controller from my view
嘿伙计们,所以我的问题是当我查看 dbo.Log 表(我的 sql 数据库)时,我不断收到错误页面未找到 404
我试图通过从另一个视图按下按钮来渲染视图,第一个视图工作正常这是我的第一个视图中的按钮
<div class="content2">
<input type="button"
value="Go to Edit"
onclick="location.href='@Url.Action("Edit", "CheckoutAttributes", 200)'" />
</div>
</body>
</html>
我知道 200 是错误的,我试图打电话给 controller,但即使没有 200 它也不起作用
这是我在 controller 中的 2 个操作,应该呈现新视图:
//[AuthorizeAdmin]
//[Area(AreaNames.Admin)]
//trying something, adding areas (end) didnt work
[HttpGet("/[area]/[controller]/[action]/{orderId:int}")]
public IActionResult Edit(int orderId)
{
Order? order = _orderService.GetOrderById(orderId);
if (order == null)
{
return NotFound(orderId);
}
if (order.OrderStatus != OrderStatus.Complete)
{
return CannotEdit(orderId, $"{nameof(order.OrderStatus)} is '{order.OrderStatus}', but '{OrderStatus.Complete}' is required.");
}
if (order.PaymentStatus != PaymentStatus.Paid)
{
return CannotEdit(orderId, $"{nameof(order.PaymentStatus)} is '{order.PaymentStatus}', but '{PaymentStatus.Paid}' is required.");
}
if (order.ShippingStatus != ShippingStatus.Delivered)
{
return CannotEdit(orderId, $"{nameof(order.ShippingStatus)} is '{order.ShippingStatus}', but '{ShippingStatus.Delivered}' is required.");
}
return Edit(order);
}
//[AuthorizeAdmin]
//[Area(AreaNames.Admin)]
//trying something, adding areas (end) didnt work
private IActionResult Edit(Order order)
{
var model = new CheckoutAttributesEditModel
{
OrderId = order.Id,
};
ParseXml(order, model);
ParseDescription(order, model);
if (!model.AllPredefinedPurchaseReasons.Any())
{
// Should not occur under normal circumstances (only when neither the xml nor the description could be parsed).
(CheckoutAttribute publishAttribute, CheckoutAttribute predefinedPurchaseReasonAttribute, CheckoutAttribute customPurchaseReasonAttribute) = GetCheckoutAttributes();
model.AllPredefinedPurchaseReasons = predefinedPurchaseReasonAttribute.CheckoutAttributeValues.ToList();
model.PublishLabel = GetLocalisedAttributeName(publishAttribute);
model.PredefinedPurchaseReasonLabel = GetLocalisedAttributeName(predefinedPurchaseReasonAttribute);
model.CustomPurchaseReasonLabel = GetLocalisedAttributeName(customPurchaseReasonAttribute);
}
ParseVCHistory(order.Id, model);
if (model.SelectedPredefinedPurchaseReason <= 0)
{
// Should be very unlikely to happen.
model.SelectedPredefinedPurchaseReason = model.AllPredefinedPurchaseReasons.First().Id;
}
//trying somehing, original was return View(model);
return View($"{Plugin.RelativeDirectoryPath}/Views/CheckoutAttributes/Edit.cshtml", model);
}
我究竟做错了什么? 不断收到 404 页面未找到提前谢谢
在端点中添加区域
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
并创建链接:
<input type="button"
value="Go to Edit"
onclick="location.href='@(Url.Action("Edit",new { controller = "CheckoutAttributes",id="123456" }))'" />
或者
<input type="button"
value="Go to Edit"
onclick="location.href='@(Url.Action("Edit","CheckoutAttributes",new { id="123456" }))'" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.