what is response.write in asp.net mvc?

前端 未结 2 1059
野的像风
野的像风 2021-01-06 04:55

This will be quite simple but

What is the best way of using classical webforms \"response.write\" in asp net MVC. Especially mvc5.

Let\'s say: I just would l

2条回答
  •  自闭症患者
    2021-01-06 05:36

    As @Shyju said you should use Content method, But there's another way by creating a custom action result, Your custom action-result could look like this::

    public class MyActionResult : ActionResult
    {
        private readonly string _content;
    
        public MyActionResult(string content)
        {
            _content = content;
        }
        public override void ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Response.Write(_content);
        }
    }
    

    Then you can use it, this way:

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";
    
            return new MyActionResult("content");
        }
    

提交回复
热议问题