Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am newbie in MVC my problem is that, my friend has developed project admin side, and I should develop web side

Now, my structere look like

-MODEL
-CONTROLLER
-VIEW
--Areas
---Admin
---Web

now inde admin and web which use same model and controller admin works normal, there is no error
but for example, I create index.cshtml within Web Areas and I wrote this code

C#
<table class="table">
    <tr>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.Label(item.TypeName)
        </td>
    </tr>
}

</table>


this is my _UsersType partial view cshtml and I used this partial in index but always Model return null where is the my problem?

and also my routeconfig look like

C#
routes.MapRoute(
               name: "AdminDefault",
               url: "Admin/{controller}/{action}/{id}",
               defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
           ).DataTokens.Add("Area", "Admin");

           routes.MapRoute(
               name: "Default",
               url: "{controller}/{action}/{id}",
               defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
               namespaces: new[] { "Otoneov2.Presentation.Mvc.Controllers" }
           ).DataTokens.Add("Area", "Web");
Posted

1 solution

None of the code you posted has anything to do with the problem.

What is relevent is the code in the controller that is returning the View you want. Apparently, you didn't pass object that the View was looking for or you passed an object that you thought contained the data but in fact contains null.
 
Share this answer
 
Comments
ammoti 11-Aug-14 17:48pm    
first of all, thanks for reply

you're absolutely right I did not understand what is the problem I am not sure maybe it can be about route configuration because when it worked it try to run HomeController.

as I said I am newbie :)

but my code which try to show look like

public virtual ActionResult Index()
{
IndexUsersTypeViewModel viewModel = new IndexUsersTypeViewModel();
ViewBag.PageIndex = this.GetPageIndex();
ViewBag.PageSize = this.GetPageSize();
ViewBag.SearchValue = this.GetSearchValue();

return View(viewModel);
}
.
Dave Kreskowiak 11-Aug-14 18:06pm    
OK, and the @model definition at the top of your Index view for that controller??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900