大家好,你可以告诉我还在学习,我想知道如何或最好的方法是为了将我的代码重用于数据库操作;例如下面的代码
// i reuse this code multiple times throughout my site but everytime I change it I must change
// all of the different Edit's each time I would like a central hub for all of it.
[Authorize]
public ActionResult Edit()
{
var ss = User.Identity.Name;
int myid = Convert.ToInt32(ss);
var buyer = (from s in db.buyers where myid == s.RegistrationID select s).FirstOrDefault();
ViewBag.RegistrationID = myid;
if (buyer != null && buyer.RegistrationID == myid)
{
return View(buyer);
}
else
{
RedirectToAction("buyerrequire");
}
return View("buyerrequire");
}
我怎样才能将这样的代码放入可重用的容器中?因此,如果我在那里更改某些内容,它将在使用该容器的整个网站上进行更改,像 _Partial 一样排序,除了 ActionResults ...感谢您的帮助..