.net MVC, dealing with json and Areas
Posted
by JoseMarmolejos
on Stack Overflow
See other posts from Stack Overflow
or by JoseMarmolejos
Published on 2010-03-12T17:16:25Z
Indexed on
2010/03/12
17:17 UTC
Read the original article
Hit count: 174
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.
© Stack Overflow or respective owner