Nuri YILMAZ
Nuri YILMAZ

Reputation: 4321

Real time JavaScript to razor pages in MVC3

Imagine some javascript codes will be add razor pages.

<script type="text/javascript">
    $(function () {
        $('#photogallery a.lightbox').lightBox();
        $('#photogallery').infiniteCarousel({ imagePath: '/Content/Images/Components/InfiniteCarousel/', autoStart: false });
        $(".flows").collapsiblePanel();
        $("[email protected]").tabs();
    });
</script>

This code need some html element defined css class by .tab and .flows. There is no sense for flows but [email protected] build in run time -because it need model-.

I would like define an attribute for controller method and I would like to add automaticaly with code.

How

[JavaScript("menu.js")]
public ActionResult Menu(object param)
{
 return PartialView(this.categoryService.GetAllCategories()[0]);
}

and razor view will have automaticaly produced code with

...
$("[email protected]").tabs(); 
...

Is it phantasy or could be implemented in real life.

Thanks

Upvotes: 1

Views: 1062

Answers (1)

SLaks
SLaks

Reputation: 887225

Your Javascript block will work fine as-is.
Just put it in the view.

Upvotes: 1

Related Questions