如何在asp.net core 2中的剃刀页面中更改图像

时间:2017-09-01 11:06:39

标签: c# razor asp.net-core-mvc-2.0

我在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的更改作出反应。

0 个答案:

没有答案