Share via


Controller Action - Nullable string parameter - Possible?

Question

Saturday, May 30, 2009 4:01 PM

It's 4:00 AM in the morning here, so I'm a bit brain dead (just saying because my question does not feel right....like I'm missing something really simple)

 One can specify a nullable int as parameter for a action method like this:  

public ActionResult Cancel(int? reason)

  But it seems you cannot use a string (or maybe other data types as well?) 

public ActionResult Cancel(string? reason)

 Can one supply a "optional" parameter then?  Like in PHP 

public ActionResult Cancel(string reason = "")

  Guess not, that also does not work

All replies (2)

Saturday, May 30, 2009 5:05 PM âś…Answered

string is reference type, so it's nullable itself (you can have variable of type string with value null).


Saturday, May 30, 2009 5:31 PM

 Got it...thanks