ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
nUnit error Ajax list Create()
Title:
B
I
{code}
?
Was hoping to be pointed in the right direction, I have an Ajax list where the Create method returns `Json(new {Content = this.RenderPartialView("ListItems/SimpleSyllabi", new[] { newSyallabus }) });` to update the list. However this returns a null reference error when tested with nUnit. Any experience with this problem?
Save Changes
Cancel
Stephan Luis
asked at 19 Dec 2018
Answers
B
I
{code}
?
you can hide the call to `RenderPartialView` with an interface: public interface IViewRender { string RenderPartialView(Controller controller, string viewName, object model = null, bool removeWhiteSpace = true); } public class ViewRender : IViewRender { public string RenderPartialView(Controller controller, string viewName, object model = null, bool removeWhiteSpace = true) { controller.RenderPartialView(viewName, model, removeWhiteSpace); } } and use the interface in the controller instead of the controller extension
Save Changes
Cancel
Omu
answered at 20 Dec 2018
Tried your suggestion ... I'm now calling RenderPartialView() through an interface as above, Autofac injected to the controller. Calling the method through the MVC pipeline / webapp is fine, but nUnit causes the same null error. Not sure what you mean 'hide' the method since the method is an extension method to the controller class and is already and has to be static. The ActionResult for Create(VM vm) is `return Json(new { Content = viewRender.RenderPartialView(this, "ListItems/SimpleSyllabi", new[] { nS }) });`
at 21 Dec 2018
Stephan Luis
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK