[英]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.