Set a property on ViewBag dynamic object in F#

前端 未结 3 935
伪装坚强ぢ
伪装坚强ぢ 2021-02-09 05:35

I have this action method in C#:

  public ActionResult Index() {
      ViewBag.Message = \"Hello\";
      return View();
  }

And this

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-09 06:13

    Just to provide a similar example, the MvcMovie example in the ASP.NET Core docs uses the following controller method:

    public IActionResult Welcome(string name, int numTimes = 1)
    {
        ViewData["Message"] = "Hello " + name;
        ViewData["NumTimes"] = numTimes;
    
        return View();
    }
    

    converted to F#:

    member this.Welcome (name : string, num_times : int) =
        this.ViewData.Add("Message", box ("Hello " + name))
        this.ViewData.Add("NumTimes", box num_times)
    
        this.View()    
    

提交回复
热议问题