KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
This 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 a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable'. How can I make this input parameter to the method optional? Here's the view model public class MyViewModel : IValidatableObject { ... public CompPhone CmpPhnF { get; set; } ... } Calling method [HttpPost, ValidateAntiForgeryToken] public ActionResult PhoneTest(MyViewModel vM) { if (ModelState.IsValid) { var cmpPhn = vM.CmpPhnF; return RedirectToAction("Edit", new { id = vM.AcntId, cmpPhn }); } ... }
Tags (comma-separated)
Save Edits
Cancel