我在C#中有一些逻辑,它控制我应该在网页上显示的图像。
基本上我想在按下按钮时更新图像,但我想在剃刀页面的控制器中进行。而不是我的javascript或html,它相当简单。
我在想某种方式: //控制器
public class APageController {
...
public IActionResult AButtonPushed() {
bool yes;
...
// some logic that changes yes
...
aPageModel.ImagePath = yes // how do I access the
? "\images\true.jpg" // razor view class from
: "\images\ohNooo.jpg" // controller
return RedirectToPage("/aPage");
}
...
}
//剃须刀页面模型
public class aPageModel : PageModel {
...
public string ImagePath {get;set;}
...
}
//和剃刀页面html
...
< img src="@Model.ImagePath"/>
...
或者也许我应该使用一些帮助器标签,强制页面对PageModel中imagePath的更改作出反应。