It works:
public ActionResult Edit(int id, CompPhone cmpPhn) { var vM = new MyViewModel(); if (cmpPhn != null) { vM.CmpPhnF = cmpPhn; } ... }
If I make cmpPhn optional:
public ActionResult Edit(int id, CompPhone? cmpPhn)
I get "Error 1" The type "MyProject.Models.CompPhone" must be an unimaginable value type in order to use it as the "T" parameter in the generic type or "System.Nullable" method.
How can I make this input parameter optional?
Here's a presentation model
public class MyViewModel : IValidatableObject { ... public CompPhone CmpPhnF { get; set; } ... }
Call method
[HttpPost, ValidateAntiForgeryToken] public ActionResult PhoneTest(MyViewModel vM) { if (ModelState.IsValid) { var cmpPhn = vM.CmpPhnF; return RedirectToAction("Edit", new { id = vM.AcntId, cmpPhn }); } ... }
source share