Razor Partial views

26 views
Skip to first unread message

Marcelo Zabani

unread,
Oct 22, 2013, 3:20:13 PM10/22/13
to simple...@googlegroups.com
Is there support for partial views? I've tried Html.Partial without success. If not, would it be too hard to implement it?

Thank you,
Marcelo.

Marcelo Zabani

unread,
Oct 22, 2013, 4:21:03 PM10/22/13
to simple...@googlegroups.com
I've messed around with Simple.Web.Razor a little bit and applied the following changes:
- Made both Handler and Model properties public to get in SimpleTemplateBase
- Created a HtmlHelper class with a string returning Partial(string viewPath) method that is as follows:

public string Partial(string viewPath)
        {
            Type partialViewType = new RazorViews().GetViewType(viewPath);
            var instance = (SimpleTemplateBase)Activator.CreateInstance(partialViewType);

            // Make the partial view inherit both the model and the handler
            instance.SetHandler(ParentView.Handler);
            instance.SetModel(ParentView.Model);
            instance.Render();

            // Return the output
            return instance.Output;
        }

- Added a public instance of HtmlHelper to SimpleTemplateBase. A property called Html that instantiates HtmlHelper passing it the view itself (this).

After this, Html.Partial seems to be working. I don't really know if this implementation is in your plans or if it is already implemented somehow, but I could certainly adapt my code to your guidelines and contribute, if you wish.
Also, it would be nice to be able to change the base class for views. Is this possible or in your plans?

Thank you,
Marcelo.

Ian Battersby

unread,
Oct 24, 2013, 10:50:50 AM10/24/13
to simple...@googlegroups.com
Looks good, and I just never got round to it as we only needed layouts for the project I was working on at the time.

I’d suggested doing a PR for that :-)

Cheers, Ian.

--
You received this message because you are subscribed to the Google Groups "SimpleWeb Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simpleweb-de...@googlegroups.com.
To post to this group, send email to simple...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/simpleweb-dev/66a78b56-193e-4d0e-bfdd-8d132e3fd38e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages