MVC controllers

I'm experimenting with the MVC Razor approach and was trying to figure out how I set up a local webapi or dynamic page that achieves the same.

What I can see is that with Xamarin I need to render the razor view and pass the HTML to the webview.

Now traditionally this view might call out to a webserver using AJAX to get some json and render it.

I'm now using SQL lite on the mobile device but want to achieve the same, although I don't need a full web request.

One approach could be for me to write out a json file to the device before I push the HTML to the webview and the view can then reference this. This seems a bit clunky so what is the best approach?


  • johanksonjohankson SEInsider, University ✭✭
    edited January 2015

    Do you mean like this?

    1. Render the razor to html (and javascript)
    2. (optional depending on network) Add json-data to the HTML generated by a local call to your Sqlite DB
    3. Pass HTML to the web view to render and execute javascript

    I think that approach is the way to go if you want to do so without calling out to an external source. However, I'm not to familiar with hybrid apps, so you probably would get better advice later on! ;)

    Or, look under the "Rending the Template"-section where you can add data to the model passed to the razor rendering directly? Might be a better approach?

    // Johan

  • DanielBayleyDanielBayley USMember

    I did consider injecting the JSON data in to the view itself, it just felt a bit messy. It also reduces the amount of reuse of the MVC/javascript which in theory I could use as a normal webview and a webAPI. I would have done this using the method described in your edit.

    What I have discovered on my travels is the hybrid webview in xLabs . This seems to allow you to call in to a c# method from HTML which I assume I could use to then generate a JSON string, but I haven't had chance to play with this yet.

  • johanksonjohankson SEInsider, University ✭✭

    The XLabs Hybrid WebView sounds nice! Please comment on it when you've tried it!

Sign In or Register to comment.