Asp.net mvc 4 如何在sql server 2008中使用asp.net mvc 4创建配置文件用户页?
我想询问有关使用asp.net mvc 4和sql server 2008创建配置文件用户页的信息。在我问之前。我在控制器中创建了如下源代码:Asp.net mvc 4 如何在sql server 2008中使用asp.net mvc 4创建配置文件用户页?,asp.net-mvc-4,webforms,Asp.net Mvc 4,Webforms,我想询问有关使用asp.net mvc 4和sql server 2008创建配置文件用户页的信息。在我问之前。我在控制器中创建了如下源代码: namespace SIDLubricants.Controllers { public class ProfileController : Controller { private Tugas_AkhirEntities db = new Tugas_AkhirEntities(); // // GET: /Profile/
namespace SIDLubricants.Controllers
{
public class ProfileController : Controller
{
private Tugas_AkhirEntities db = new Tugas_AkhirEntities();
//
// GET: /Profile/
public ActionResult Index(LoginModel model)
{
var m_cp_customer = from cp in db.M_cp_Customer.Include(m => m.User) where cp.Id == model.Id select cp;
return View(m_cp_customer.ToList());
我创建了如下视图:
<div id="content" class="span12">
<div class="row-fluid sortable">
<div class="box span12">
<div class="box-header well">
<h2>Contact Person Profile</h2>
<table>
<% using (Html.BeginForm()) { %>
<%: Html.AntiForgeryToken() %>
<%: Html.ValidationSummary(true) %>
<tr>
<td><%: Html.DisplayName("Contact Person Customer") %></td>
<td><%: Html.DisplayFor(model => model.kd_cp_customer) %></td>
</tr>
<tr>
<td><%: Html.DisplayName("First Name") %></td>
<td><%: Html.DisplayFor(model => model.NamaDepan) %></td>
</tr>
<tr>
<td><%: Html.DisplayName("Last Name") %></td>
<td><%: Html.DisplayFor(model => model.NamaBelakang) %></td>
</tr>
<tr>
<td><%: Html.DisplayName("Birth Date") %></td>
<td><%: Html.DisplayFor(model => model.Tgl_Lahir) %></td>
</tr>
<tr>
<td><%: Html.DisplayName("Gender") %></td>
<td><%: Html.DisplayFor(model => model.JenisKelamin) %></td>
</tr>
<tr>
<td><%: Html.DisplayName("Address") %></td>
<td><%: Html.DisplayFor(model => model.Alamat) %></td>
</tr>
<tr>
<td><%: Html.DisplayName("City") %></td>
<td><%: Html.DisplayFor(model => model.Kota) %></td>
</tr>
<tr>
<td><%: Html.DisplayName("Province") %></td>
<td><%: Html.DisplayFor(model => model.Provinsi) %></td>
</tr>
<tr>
<td><%: Html.DisplayName("Zip Code") %></td>
<td><%: Html.DisplayFor(model => model.KodePos) %></td>
</tr>
<tr>
<td><%: Html.DisplayName("Phone") %></td>
<td><%: Html.DisplayFor(model => model.Telp) %></td>
</tr>
<tr>
<td><%: Html.DisplayName("Mobile") %></td>
<td><%: Html.DisplayFor(model => model.Mobile) %></td>
</tr>
<tr>
<td><%: Html.DisplayName("Email") %></td>
<td><%: Html.DisplayFor(model => model.Email) %></td>
</tr>
<tr>
<td><%: Html.DisplayName("UserName") %></td>
<td><%: Html.DisplayFor(model => model.User.userName) %></td>
</tr>
<tr>
<td><input type="button" onclick="" value="edit" /></td>
<td> <input type="submit" value="Delete" /></td>
</tr>
<% } %>
</table>
</div>
</div><!--/span-->
</div><!--/row-->
你能帮我一下吗。我想最后的输出是显示所有的数据后,配置文件用户的行动登录。谢谢您…问题不是SQL Server 2008,问题是您返回的实体与用户id匹配。您需要向查询中添加
FirstOrDefault()
,这样您就不会返回IEnumerable
,而是返回一个M_cp_客户
实体
public ActionResult Index(LoginModel model)
{
M_cp_Customer m_cp_customer = (from cp in db.M_cp_Customer.Include(m => m.User)
where cp.Id == model.Id
select cp).FirstOrDefault();
return View(m_cp_customer);
}
你读到错误信息了吗?它就在那里写着怎么了。您的视图需要一个
sidlooleries.Models.M\u cp\u Customer
的实例,但在控制器中,您需要ToList()
,生成一个集合。谢谢Cornem。。对不起,我是asp.net新手,所以我仍然不知道我的源代码是否有错误。。我使用的标题问题是SQL Server 2008,因为我使用asp.net mvc 4和SQL Server 2008开发了此应用程序。:)没问题,祝你的项目顺利,学习ASP.NET!
public ActionResult Index(LoginModel model)
{
M_cp_Customer m_cp_customer = (from cp in db.M_cp_Customer.Include(m => m.User)
where cp.Id == model.Id
select cp).FirstOrDefault();
return View(m_cp_customer);
}