开发者

How do I route this in ASP.NET MVC

Im new to MVC.

I have a controller for some charts (ChartsController), where I have an action result

public ActionResult TheChart { ...etc

I then have a View which displays the chart (its a Highcharts chart using javascript). This calls its data via this

public JsonResult GetData(string id) { ..etc

All works well.

I want to now add a parameter so that I can slightly change my javascript in the view for certain conditions. (Display for printing) I was thinking something like

public ActionResult TheChart(string mediaType)
{ 
     if (medi开发者_运维知识库aType="print"){
            ViewData["pdf"] = true;
     }
}

Then I can grab this in the view.

The problem is that now my JsonResult doesnt work ( I think due to the routing ). Any ideas of how to solve this?


it is because you have (string mediaType)

what you need is a new route like this:

routes.MapRoute("all-user", "Controller/TheChart/{mediaType}",
                        new { controller = "Controller", action = "TheChart"});

this goes inside your Global.asax file incase you havent used these yet.


Is this just a typo here or did you really write if (mediaType="print"){? There is an equal sign missing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜