Сохранение модели внутри модели

Итак, у меня есть этоProperty класс, который определяетсяID Name а такжеDataType. DataType уже заполнен статическими значениями и используется в качестве раскрывающегося списка.

Теперь, когда пользователь выбирает определенное значение из списка,List Если быть точным, приложение открывает дополнительное текстовое поле и кнопку для заполнения этого списка.

Модели идут так.

Модель недвижимости

public class Property
{
    public int ID {get; set;}
    public string Name {get; set;}

    public int DTypeID {get; set;}
    public virtual DType DTypes {get; set;}
}

Список моделей

public class DList
{
    public int ID {get; set;}
    public int PropertyID {get; set;}
    public string ListValue {get; set;}
}

И это то, что я сделал до сих пор.

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <div class="labels tableRow">
            <div class="editor-label tableCell">
                <p>
                    Name
                </p>
                <p>
                    Data Type
                </p>
            </div>
            <div class="editor-field tableCell">
                <p>
                    @Html.TextBoxFor(model => model.Name, new { @class = "textEntry" })
                    @Html.ValidationMessageFor(model => model.Name)
                </p>
                <p>
                    @Html.DropDownList("DTypeID", (SelectList)ViewBag.DTypeID, new { @class = "dropdown", @onchange = "DropDownChange()"})
                    @Html.ValidationMessageFor(model => model.DTypeID)
                </p>
            </div>
        </div>


        <div id="StaticListUI" class="invis">
            <div class="labels tableRow">
                <div class="editor-label tableCell">
                    <p>
                        @*here goes list*@
                    </p>
                </div>
                <div class="editor-field tableCell">
                    <p>
                        @*here goes textbox*@
                        @Html.TextBox("textboxList")
                    </p>
                    <p>
                        @*here goes button*@
                        <button name="button" value="add">Add</button>
                    </p>
                </div>

            </div>

        </div>


        <p class="labels">
            @*<input type="submit" value="Create" />*@
            <button name="button" value="create">Create</button> |
            <input type="button" value="Back" onClick='javascript:location.href = "@Url.Action("Index", "Property")";' />
        </p>
    </fieldset>
}

Таким образом, чтобы зафиксировать, какая кнопка нажата, я сделал это для своего контроллера.

[HttpPost]
public ActionResult Create(string button, string textboxList, Property property)
{

    if (button == "add")
    {
        var lastProperty = db.Properties.OrderByDescending(p => p.PropertyID).FirstOrDefault();
        int propID;
        if (lastProperty == null)
        {
            propID = 1;
        }
        else
        {
            propID = 1 + lastProperty.PropertyID;
        }

        DList dList = new DList();

        dList.PropertyID = propID;
        dList.ListValue = textboxList;

        db.DLists.Add(dList);

        return View(property);
    }

    string projectID = System.Web.HttpContext.Current.Session["_SelectedProjectID"].ToString();
    int projID = Convert.ToInt32(projectID);
    property.ProjectID = projID;
    property.DateCreated = DateTime.Now;
    property.DateEdited = DateTime.Now;

    if (ModelState.IsValid)
    {
        db.Properties.Add(property);
        db.SaveChanges();
        return RedirectToAction("Index");
    }

    ViewBag.DTypeID = new SelectList(db.DType, "ID", "Name", property.DTypeID);
    return View(property);
}

И проблема в том, что когда я нажимаюAdd Кнопка, он по-прежнему отправляет чек наModelState.IsValid, который не должен ". Что я сделал не так, или я сделал что-то правильно :(

Примечание: все остальное в основном работает.

EDIT

Поэтому я изменил контроллер, чтобы принимать параметры от нажатия кнопки по-разному. Но все же чего-то не хватает ...

    [ActionName("Create")]
    [AcceptVerbs(HttpVerbs.Post)]
    [AcceptParameter(Name = "button", Value = "add")]
    public ActionResult Create_Add(string textboxList)
    {
        var lastProperty = db.Properties.OrderByDescending(p => p.PropertyID).FirstOrDefault();
        int propID;
        if (lastProperty == null)
        {
            propID = 1;
        }
        else
        {
            propID = 1 + lastProperty.PropertyID;
        }

        DList dList = new DList();

        dList.PropertyID = propID;
        dList.ListValue = textboxList;

        db.DLists.Add(dList);
        db.SaveChanges();



        return View();
    }

    [AcceptVerbs(HttpVerbs.Post)]
    [AcceptParameter(Name="button", Value="create")]
    public ActionResult Create(Property property)
    {
        string projectID = System.Web.HttpContext.Current.Session["_SelectedProjectID"].ToString();
        int projID = Convert.ToInt32(projectID);
        property.ProjectID = projID;
        property.DateCreated = DateTime.Now;
        property.DateEdited = DateTime.Now;

        if (ModelState.IsValid)
        {
            db.Properties.Add(property);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        ViewBag.DTypeID = new SelectList(db.DType, "ID", "Name", property.DTypeID);
        return View(property);
    }


    public class AcceptParameterAttribute : ActionMethodSelectorAttribute
    {
        public string Name { get; set; }
        public string Value { get; set; }

        public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo)
        {
            var req = controllerContext.RequestContext.HttpContext.Request;
            return req.Form[this.Name] == this.Value;
        }
    }

Ответы на вопрос(1)

Ваш ответ на вопрос