morteza naeimabadi
morteza naeimabadi

Reputation: 1

How to fill the model class in asp.net mvc2?

I have model such as:

 public class AdminArticleModel
{
    public string Author
    {
        get;
        set;
    }
    public string Title
    {
        get;
        set;
    }
    public DateTime? SubmitedDate
    {
        get;
        set;
    }
    public System.Data.Objects.DataClasses.EntityCollection<jpharmacareProject.ArticleFile> thearticleFiles
    {
        get;
        set;
    }
}

And In my action I am using code below:

[OutputCache(Duration = 0, VaryByParam = "None")]
    public ActionResult Submitted()
    {

        string userID = User.Identity.Name;
        List<AdminArticleModel> query = (from article in db.Articles
                                        where article.User.userID == userID
                                        && article.IsTempArticle == false
                                         select new AdminArticleModel() { Author = article.User.FirstName, 
                                             Title = article.Title,SubmitedDate=article.SubmissionDate,
                                             thearticleFiles = article.ArticleFiles
                                              })
                                        .ToList<AdminArticleModel>();


        ViewData["temps"] = query;
        return View();

    }

And I have created a strongly typed view to my model.but when i browse my action it is saying that the model is null.why it is not filled?how to fill it?

Upvotes: 0

Views: 120

Answers (1)

BNL
BNL

Reputation: 7133

You have not specified your model. You have created a ViewData node.

To specify your model, change:

return View();

To:

return View(query);

See this article for more details about the Model and ViewData objects.

http://www.mikesdotnetting.com/Article/105/ASP.NET-MVC-Partial-Views-and-Strongly-Typed-Custom-ViewModels

Upvotes: 2

Related Questions