.net MVC, dealing with json and Areas
- by JoseMarmolejos
When not using areas dealing with the url for the JsonResults from the clientside is not much of a pain, usually you can get away with hardcoding the url into your json calls and get away with it. Problem arises when you have different areas and you don't want to update all your links when you move a controller (and its views) from one area to the other. I'm not very satisfied with the way I'm handling this scenario by having this chunk of code inside every view:
<script type="text/javascript">
var ControllerActions = {
JsonSearch: '<%= Url.Action("JsonSearch") %>/',
JsonDelete: '<%= Url.Action("JsonDelete") %>/',
Edit: '<%= Url.Action("Edit") %>/',
Delete: '<%= Url.Action("Delete") %>/'
}
</script>
While it does work no matter where I place the views/controllers I wonder if there's a more elegant to do this.