如何在同一视图上填充数据并在此更新。 [英] How can I populate data on same view and update also on this.
本文介绍了如何在同一视图上填充数据并在此更新。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
服务器错误 ' /'应用程序。
当前请求 操作' AddAlbum' 控制器类型' AccountController' 以下操作方法之间的模糊:
System.Web.Mvc.ActionResult类型为KDFOTOZ.Controllers.AccountController的AddAlbum()
System.Web.Mvc.ActionResult AddAlbum( Int32 )
我尝试了什么:
href=@Url.Action(< span class =code-string> AddAlbum, 帐户, new {Id = r.Id})
public ActionResult AddAlbum()
{
if (会话[ 用户] == null && Convert.ToInt32(会话[ 用户])< ; = 0 )
{
return RedirectToAction( 登录, 帐户跨度>);
}
AlbumModel AM = new AlbumModel();
return 查看(AM);
}
public ActionResult AddAlbum( Int32 Id)
{
AlbumModel A = new AlbumModel();
使用(kdfotozEntities db = new kdfotozEntities())
{
tbl_Album obj =( from n in db.tbl_Album 其中 n.Id == Id select n).FirstOrDefault();
if (obj!= null )
{
A. Id = obj.Id;
A.AlbumName = obj.AlbumName;
A.Description = obj.AlbumDesc;
A.CoverFilePath = obj.CoverImgPath;
A.DateAdded = obj.DateAdded;
}
}
返回查看(A);
}
解决方案
您好,
您可能需要实现指向不同操作方法的自定义路由。这是因为在控制器上最多只能有2个具有相同名称的操作方法,这意味着可以在[HttpPost或[HttpGet]上调用您的操作 - 这是默认值。
将此讨论读作: c# - 路由:当前的操作请求[...]在以下操作方法之间是不明确的 - Stack Overflow [ ^
Server Error in '/' Application.
The current request for action 'AddAlbum' on controller type 'AccountController' is ambiguous between the following action methods:
System.Web.Mvc.ActionResult AddAlbum() on type KDFOTOZ.Controllers.AccountController
System.Web.Mvc.ActionResult AddAlbum(Int32) on type KDFOTOZ.Controllers.AccountController
What I have tried:
href=@Url.Action("AddAlbum", "Account", new { Id = r.Id })
public ActionResult AddAlbum()
{
if (Session["User"] == null && Convert.ToInt32(Session["User"]) <= 0)
{
return RedirectToAction("Login", "Account");
}
AlbumModel AM = new AlbumModel();
return View(AM);
}
public ActionResult AddAlbum(Int32 Id)
{
AlbumModel A = new AlbumModel();
using (kdfotozEntities db = new kdfotozEntities())
{
tbl_Album obj = (from n in db.tbl_Album where n.Id == Id select n).FirstOrDefault();
if (obj != null)
{
A.Id = obj.Id;
A.AlbumName = obj.AlbumName;
A.Description = obj.AlbumDesc;
A.CoverFilePath = obj.CoverImgPath;
A.DateAdded = obj.DateAdded;
}
}
return View(A);
}
解决方案
Hi,
You may need to implement a custom routes that is pointing to a different action methods.This is because you can only have a maximum of 2 action methods with the same name on a controller, it means that your action can be invoked on [HttpPost or [HttpGet] - which is the default.
Give this discussion a read: c# - Routing: The current request for action [...] is ambiguous between the following action methods - Stack Overflow[^]
这篇关于如何在同一视图上填充数据并在此更新。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文