我有这个控制器:
- (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier {
UIStoryboardSegue *theSegue;
NSLog(@"Unwind called");
if ([fromViewController isKindOfClass:[SetDetailViewController class]]) {
theSegue = [ZoomOutSegue segueWithIdentifier:identifier source:fromViewController destination:toViewController performHandler:^(void){}];
} else {
theSegue = [super segueForUnwindingToViewController:toViewController fromViewController:fromViewController identifier:identifier];
}
return theSegue;
}
这一行
public ActionResult Index(UserDetails user)
{
user.UserEmail = "Email";
return View();
}
如何从视图中的控制器(在UserEmail的输入框中)中过去一个值?
感谢您的帮助 斯蒂芬
答案 0 :(得分:2)
将UserDetails
对象传递给视图。
public ActionResult Index(UserDetails user)
{
user.UserEmail = "Email";
return View(user);
}
假设您的剃刀视图(Index.cshtml
)强烈输入UserDetails
@model UserDetails
@Html.DisplayNameFor(model => model.UserEmail)
@Html.EditorFor(model => model.UserEmail)
答案 1 :(得分:-1)
有多种方法可以将值从控制器传递到视图..我会使用viewData和viewBag:
public ActionResult Index(UserDetails user)
{
user.UserEmail = "Email";
ViewData["ArbitraryName"] = user;
return View();
}
在您看来:
@Html.DisplayNameFor(model => model.UserEmail)
@Html.EditorFor(model => model.UserEmail)
@{ var user = ViewBag.ArbitraryName;}
要从那里访问特定数据,请使用@user.YourData
有关此特定主题的更多信息,请参阅此处: https://chsakell.com/2013/05/02/4-basic-ways-to-pass-data-from-controller-to-view-in-asp-net-mvc/