MVC Linq to sql 查出来的数据怎样显示在View 页

yujinliang yujinliang 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
HomeController.cs

public ActionResult Edit(int? id)
{
ViewData["id"] = id;
var dataContext = new MovieDataContext();

var movies = from m in dataContext.Movies
where m.id == 1
select m;
return View(movies);
}

VIEW :


<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="test.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Edit
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>
Edit</h2>
<%= Html.ValidationSummary() %>
<% using (Html.BeginForm())
{%>
<fieldset>
<legend>Fields</legend>
<p>
<label for="Title">
ProductName:</label>
<%= Html.TextBox("Title", ViewData.Model)%>
<%= Html.ValidationMessage("Title", "*") %>
</p>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
<% } %>
<div>
<%=Html.ActionLink("Back to List", "Index") %>
</div>
</asp:Content>




=ViewData.Model

这样写输出的是SQL语句,

我想取里面的字段 =ViewData.Model.id , = ViewData.Model.Title 里面没有这俩个属性是为什么呢?

怎么样显示在View 页呀。

...全文

相关推荐

评论 10
收藏 已收藏
分享
返回顶部
yujinliang
LINQ 8,492 成员 4,736 内容