ASP.NET MVC IDENTITY_INSERT set to OFF

My HomeController has the following code:

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();
            }
        }

And this is the view for the Create method

<%@ 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>

The problem that I get when I try to send data is an InnerException, which indicates that IDENTITY_INSERT is disabled. However, the identifier in my article (called storyId) is set to Auto Increment and is also set to Identity, as well as the primary key / index.

How to fix this problem? Thank.

+3
source share
1 answer

Did you create a Linq To SQL DBML file and then change the database schema to anything to automatically grow? I think you might have changed the schema, but forgot to update the linq constructor.

.

+3

Source: https://habr.com/ru/post/1783706/


All Articles