开发者

Display Dynamic Content in ASP.NET MVC 3

I have the following structure:

  1. Site.Master

  2. Home - View

  3. HomeController - 开发者_如何学GoController

In the Site.Master I have a header that contains several ActionLinks, one of which is a Faq. In the Home view I have HTML that essentially displays static content, but, in the center pane/div I want to have dynamic content, based on certain HTML.ActionLinks that the user clicks on. So, for example, initially, I want the center DIV to display an intro - but if the user clicks on my Faq ActionLink, I want the center DIV to display content specific to my Faq.

In the HomeController I have the following:

[HttpGet]
    public ActionResult Intro()
    {
        var introRequest = _gatewayService.GetContent(new GetContentRequest { Content = ContentTypes.Introduction });

        ViewData["content"] = introRequest.Result;

        return View();
    }

 [HttpGet]
    public ActionResult Faq()
    {
        var faqRequest = _gatewayService.GetContent(new GetContentRequest { Content = ContentTypes.Faq });

        ViewData["content"] = faqRequest.Result;

        return View();
    }

The idea would be that the action link for Faq would look something like:

<%= Html.ActionLink("Faq","Faq","Home") %> 


As @Valamas said, use Ajax.ActionLink. For example,
In markup:

<div id=”faqContent”>
   @Ajax.ActionLink(“Click here to see FAQ!”,
      “Faq”,
      new AjaxOptions{
         UpdateTargetId=”faqContent”,
         InsertionMode=InsertionMode.Replace,
         HttpMethod=”GET”
      })
</div>

And in controller:

public ActionResult Faq()
{
    var faqRequest = _gatewayService.GetContent(new GetContentRequest { Content = ContentTypes.Faq });

    return PartialView("Faq", faqRequest.Result);
}

And finally have a partial view Faq.chtml with required html for FAQ.


First you will need to change the result of your action methods in your controller,instead of actionresult you can use jsonresult Second, in the view you can use jquery to load the dynamic content

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜