Я работаю над созданием блога с ASP.Net 4, MVC 3, Razor и C#. Есть 2 отдельных стола. 1 для фактического сообщения в блоге и таблицы отношений для категорий. Категории отображаются в раскрывающемся меню. Я хочу добавить возможность добавления новой категории с помощью Ajax, чтобы пользователь не потерял то, что уже ввел в форму. Что было бы лучшим способом добиться этого? Вот что я имею прямо сейчас.Добавить категорию Динамически ASP.Net 4 MVC3 C#
Controller Код
public ActionResult Create()
{
ViewBag.category_id = new SelectList(_db.Categories, "id", "category_name");
return View();
}
Razor Посмотреть
@model NPP.Models.News
@{
ViewBag.Title = "Create News Item";
}
<h2>Create News Item</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>News</legend>
<div class="editor-label">
@Html.LabelFor(model => model.news_title, "Title")
</div>
<div class="editor-field">
@Html.EditorFor(model => model.news_title)
@Html.ValidationMessageFor(model => model.news_title)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.news_content, "Content")
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.news_content)
@Html.ValidationMessageFor(model => model.news_content)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.news_teaser, "Teaser (optional)")
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.news_teaser)
@Html.ValidationMessageFor(model => model.news_teaser)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.category_id, "Category")
</div>
<div class="editor-field">
@Html.DropDownList("category_id", String.Empty)
@Html.ValidationMessageFor(model => model.category_id)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
Спасибо за помощь в заранее. Моя страница макета включает jquery, который я бы предпочел использовать.