Asp.net mvc ASP.NET MVC标识\u插入设置为关闭
我的HomeController中有以下代码:Asp.net mvc ASP.NET MVC标识\u插入设置为关闭,asp.net-mvc,entity-framework,identity-insert,Asp.net Mvc,Entity Framework,Identity Insert,我的HomeController中有以下代码: public ActionResult Create() { return View(); } [ValidateInput(false)] [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create([Bind(Exclude = "Id")]Article articleToCreate
public ActionResult Create()
{
return View();
}
[ValidateInput(false)]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude = "Id")]Article articleToCreate)
{
if (!ModelState.IsValid)
return View();
try
{
_db.AddToArticleSet(articleToCreate);
articleToCreate.posted = DateTime.Now;
_db.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
这是Create方法的视图
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Create
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="create">
<h2>Create News Article <span>( <%=Html.ActionLink("Cancel", "Index") %> )</span></h2>
<% using (Html.BeginForm()) {%>
<fieldset>
<legend>Fields</legend>
<p>
<label for="headline">Headline</label>
<%= Html.TextBox("headline") %>
</p>
<p>
<label for="story">Story <span>( HTML Allowed )</span></label>
<%= Html.TextArea("story") %>
</p>
<p>
<label for="image">Image URL</label>
<%= Html.TextBox("image") %>
</p>
<p>
<input type="submit" value="Post" />
</p>
</fieldset>
<% } %>
</div>
<!-- END div#create -->
</asp:Content>
创造
创建新闻文章()
领域
大字标题
故事(允许使用HTML)
图像URL
当我尝试提交数据时遇到的问题是InnerException说IDENTITY_INSERT设置为off。但是,我的文章表中的ID(称为storyId)设置为自动递增,并且还设置为标识和主键/索引
如何解决此问题?谢谢。您是否创建了Linq To SQL DBML文件,然后将数据库模式更改为all以实现自动增量?我认为您可能已经更改了模式,但忘记了更新linq设计器
只需删除设计器中的表并将其从数据库中拖动。
我会:一旦我得到了答案,我就很乐意接受。如果你没有得到你需要的答案,那么考虑用一些反馈来重新回答问题,以提高响应。我看到你的问题中至少有两个有人提供了反馈,而你根本没有回答。此外,如果有任何帮助,您的HTML是无效的。p
标记中的输入字段?!考虑使用<代码> div < /代码>!天才:)我刚把它刷新了。我也接受了你的答案!;)你觉得你也能帮上忙吗?我把我对你另一个问题的答案贴了出来。