enum args in controller action methods?http://forums.asp.net/t/1440432.aspx/1?enum+args+in+controller+action+methods+Fri, 26 Jun 2009 16:22:44 -040014404323260490http://forums.asp.net/p/1440432/3260490.aspx/1?enum+args+in+controller+action+methods+enum args in controller action methods? <p>Is it possible use an enum argument in a controller action method? &nbsp; How would javascript represent an enum arg value when calling a controller action?</p> <p><br> </p> <p><br> </p> <p>thanks!</p> 2009-06-26T15:08:29-04:003260557http://forums.asp.net/p/1440432/3260557.aspx/1?Re+enum+args+in+controller+action+methods+Re: enum args in controller action methods? <p>&nbsp;I've done it as a member property of an object that is getting model bound, so the DMB can definitely do it that way (in that case, I represented the enum as a dropdownlist).&nbsp; NOt sure if it would work on its own.&nbsp; going from JS might be more complex; I'll have to think about it.</p> 2009-06-26T15:41:09-04:003260628http://forums.asp.net/p/1440432/3260628.aspx/1?Re+enum+args+in+controller+action+methods+Re: enum args in controller action methods? <p>Yes, it is possible. You can submit either the integer value or the string name of the enum value.&nbsp;A quick experiment verifies this. For example, in HomeController.cs write this. </p> <pre class="prettyprint">public class HomeController : Controller { public ActionResult Index() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult Index(MyEnum value) { ViewData[&quot;Message&quot;] = value.ToString(); return View(); } } public enum MyEnum { Foo, Bar, Baz }</pre> <P><BR>Then in Index.aspx include the form:</P><pre class="prettyprint"> &lt;% using (Html.BeginForm()) { %&gt; &lt;%= Html.TextBox("value") %&gt; &lt;input type="submit" /&gt; &lt;% } %&gt;</pre> <p>And try submitting the value 0 then try submitting Bar and you'll see they both work.<br> </p> <p>Phil&nbsp;</p> 2009-06-26T16:22:44-04:00