~/Helpers/Helpers.cs に次のものがあります。
namespace AdjusterSave.Helpers
{
public class Helpers : Controller
{
// various methods such as the following...
public void GetDropdowns()
{
}
}
}
~/Controllers/AdjusterController.cs ファイルでこれらを次のように含めて使用しようとしています。
using AdjusterSave.Helpers;
ただし、メソッドを使用しようとすると、引き続き次のエラーが発生します。これを呼び出すと:
GetDropdowns();
次のエラーが表示されます。
「GetDropdowns」という名前は、現在のコンテキストには存在しません。
編集:
そのような方法を使用しようとしています (~/Controllers/AdjusterController.cs 内):
public ActionResult ViewProfile()
{
// a bunch of code like this:
User user = db.Users.Where(x => x.username == HttpContext.User.Identity.Name).FirstOrDefault();
AdjusterViewProfileInfo model = new AdjusterViewProfileInfo();
// get name
model.namePrefix = user.namePrefix;
model.firstName = user.firstName;
model.middleInitial = user.middleInitial;
model.lastName = user.lastName;
model.nameSuffix = user.nameSuffix;
// end then, finally,
GetDropdowns();
// followed by...
TempData["CurrentPage"] = "ViewProfile";
return View("", _layout, model);
}
編集:
GetDropdowns 例:
public void GetDropdowns(this Controller controller)
{
// get name prefixes
List<SelectListItem> prefixList = new List<SelectListItem>();
prefixList.Add(new SelectListItem { Value = "Mr.", Text = "Mr." });
prefixList.Add(new SelectListItem { Value = "Mrs.", Text = "Mrs." });
prefixList.Add(new SelectListItem { Value = "Ms.", Text = "Ms." });
ViewBag.PrefixList = new SelectList(prefixList, "Value", "Text");
}