Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Textarea赢得';不能使用jQuery保存到数据库_C#_Jquery_Asp.net Mvc_Entity Framework_Asp.net Mvc 4 - Fatal编程技术网

C# Textarea赢得';不能使用jQuery保存到数据库

C# Textarea赢得';不能使用jQuery保存到数据库,c#,jquery,asp.net-mvc,entity-framework,asp.net-mvc-4,C#,Jquery,Asp.net Mvc,Entity Framework,Asp.net Mvc 4,我正在尝试使用jQuery动态添加表单字段,并将输入保存到数据库中。除了textarea之外,所有字段都保存到数据库中。我不确定是什么问题 查看 @model DailyTaskList.Models.DTL_Tasks @{ var db = new DailyTaskList.Models.DailyTaskListEntities(); var options = db.DTL_UserOptions.Where(u => u.UserProfile.UserId == WebMa

我正在尝试使用jQuery动态添加表单字段,并将输入保存到数据库中。除了textarea之外,所有字段都保存到数据库中。我不确定是什么问题

查看

@model DailyTaskList.Models.DTL_Tasks

@{
var db = new DailyTaskList.Models.DailyTaskListEntities();
var options = db.DTL_UserOptions.Where(u => u.UserProfile.UserId == WebMatrix.WebData.WebSecurity.CurrentUserId);
var priority = db.DTL_Tasks.Select(p => p.Priority).FirstOrDefault();
var customerNames = db.DTL_Customers.Select(c => c.CustomerName);
var userSelectedTasks = options.Select(o => o.DTL_TaskTypes);


SelectList userSelectedTasksList = new SelectList(userSelectedTasks);
var priorityListItems = new SelectListItem[] {
    new SelectListItem(){ Text="", Value="0" },
    new SelectListItem(){ Text="Low", Value="1" },
    new SelectListItem(){ Text="Medium", Value="2" },
    new SelectListItem(){ Text="High", Value="3" },
    new SelectListItem(){ Text="Highest", Value="4" }
};

using (Html.BeginForm("Index", "NewTask", FormMethod.Post, new { id = "new-task-form" })) {
@Html.ValidationSummary(true)

    // Original form fields
    <div class="new-task-form-wrapper">
        <div class="form-group">
            <label>Customer:</label>
            @Html.DropDownListFor(model => model.CustomerId, new SelectList(db.DTL_Customers, "CustomerId", "CustomerName"), new { @class = "form-control", id = "Customer_0" })
        </div>
        <div class="form-group">
            <div class="row">
                <div class="col-sm-10">
                    <label>Activity:</label>
                    @Html.DropDownListFor(model => model.TaskTypeId, new SelectList(userSelectedTasks, "TaskTypeId", "TaskName"), new { @class = "form-control", id = "Activity_0" })
                </div>
                <div class="col-sm-2">
                    <label>Priority:</label>
                    @Html.DropDownListFor(model => model.Priority, priorityListItems, new { @class = "form-control", id = "Priority_0" })
                </div>
            </div>
        </div>
        <div class="form-group">
            <label>Title:</label>
            @Html.TextBoxFor(model => model.TaskTitle, new { @class = "form-control", id = "Title_0" })
        </div>
        <div class="form-group description">
            <label>Description:</label>
            @Html.TextAreaFor(model => model.TaskDescription, new { @class = "form-control", id = "Description_0" })
        </div>
    </div>

    // Additional form fields
    <div id="additional-form-fields_0" class="hide new-task-form-wrapper">
        <div class="form-group">
            <label>Customer:</label>
            @Html.DropDownListFor(model => model.CustomerId, new SelectList(db.DTL_Customers, "CustomerId", "CustomerName"), new { @class = "form-control", id = "Customer_1" })
        </div>
        <div class="form-group">
            <div class="row">
                <div class="col-sm-10">
                    <label>Activity:</label>
                    @Html.DropDownListFor(model => model.TaskTypeId, new SelectList(userSelectedTasks, "TaskTypeId", "TaskName"), new { @class = "form-control", id = "Activity_1" })
                </div>
                <div class="col-sm-2">
                    <label>Priority:</label>
                    @Html.DropDownListFor(model => model.Priority, priorityListItems, new { @class = "form-control", id = "Priority_1" })
                </div>
            </div>
        </div>
        <div class="form-group">
            <label>Title:</label>
            @Html.TextBoxFor(model => model.TaskTitle, new { @class = "form-control", id = "Title_1" })
        </div>
        <div class="form-group description">
            <label>Description:</label>
            @Html.TextAreaFor(model => model.TaskDescription, new { @class = "form-control", id = "Description_1" })
        </div>
    </div>

    // Form controls
    <div class="form-group">
        <button type="submit" class="btn btn-default" value="Create">Submit</button>
        <div class="btn btn-default" id="addnew">+</div>
        @*<div class="btn btn-default" id="remove">-</div>*@
    </div>
  }
}

您的文本区域的名称是
tasksdescription
,因此更合适的选择器是:

TaskDescription: $(this).find("textarea[name^='TaskDescription']").val()

您正在选择名称,但我没有看到您为该字段设置名称。如果您查看源代码,文本区域中是否有名称?
TaskDescription: $(this).find("textarea[name^='TaskDescription']").val()