开发者

MVC: Model is null in a view's aspx

开发者 https://www.devze.com 2022-12-22 03:53 出处:网络
I\'m following this MVC tutorial and when I add a View for the Edit action, Model is null in the following snippet on the .aspx page:

I'm following this MVC tutorial and when I add a View for the Edit action, Model is null in the following snippet on the .aspx page:

<%= Html.TextBox("Id", Model.Id) %>

I'm learning MVC, so please understand if I'm doing a dumb thing. But as far as I can see, I've following the steps in the tutorial pretty well. And actually added the Create action and it works correctly.

Ideas appreciate开发者_开发百科d.


Is your view strongly typed?

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/TwoColumnUI.Master" Inherits="System.Web.Mvc.ViewPage<MyObject>" %>

then you would need to pass in an object of type MyObject from your controller action method

return View(new MyObject() { Id = 42 } );


Did you set the model in the controller? What does your controller method look like? Are you just returning View()? You need to pass the model as a parameter to that call like they do in the example:

return View(movieToEdit);

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号