Question

I am trying to update user in my model object

   public ActionResult AddJob(JobQueue job,HttpPostedFileBase file)
    {
       job.User = "itdev";

       TryUpdateModel(job) 

       if (ModelState.IsValid)//Always returns false
       {

       }
    }

MODEL

   public class JobQueue { 
   [Required] 
   [Display(Name="JobId")] 
   public string JobId { get; set; } 

   [Required] [Display(Name = "FileName")] 
   public string FileName { get; set; } 

   [Required] 
   [Display(Name = "Job Run Date")] 
   public DateTime JobRunDate { get; set; } 

   [Required] 
   [Display(Name = "Email")] 
   public string Mail { get; set; } 

   [Required] 
   [Display(Name = "User")] 
   public string User { get; set; }

I tried using TryUpdateModel(job) and UpdateModel(job) after assigning the values.Both of these does not seem to update the model because ModelState.IsValid return false.Can someone point me in the right directions?I am using MVC3

Thanks,

Sab

Was it helpful?

Solution

I may be wrong here, but I think job.User = "itdev"; should be sufficent to update the model without using the TryUpdateModel(job) thats how we do it in our site anyway. I have never need to use any method to actually update the model itself. Just assigned values manually.

It depends on how your model is setup I guess.

You should probably post the code for your model just in case my answer isnt helpful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top