Using a dynamic type type with a typical MVC type

I have a page for creating dynamic objects.

<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> ... 

I have two actions:

 public ActionResult Create() { dynamic model = ... return View(model); } [HttpPost] public ActionResult Create(dynamic(1) entity) { ... } 

Well, the problem is that the entity is empty from the page. If I change the dynamics in (1) for a real type, it works fine.

0
dynamic asp.net-mvc view
source share
1 answer

I’m not 100% at that, but I think that the problem is that by default the connecting device has no idea what to do with the β€œdynamic” type, since it does not have any specific properties for reflection. You will need to write your own middleware that will use the form input names, which is dangerous / unreliable because the form can be modified on the client side.

I have studied dynamically typed ViewPages before (here on SO actually: Dynamically typed ViewPage ), and I came to the conclusion that it really doesn't give you anything in most situations. At least not yet (MVC 3+ may be different history).

And here are some notes from Phil Haack on this subject: http://haacked.com/archive/2009/08/26/method-missing-csharp-4.aspx

0
source share

All Articles