안녕하세요. 저는 Mvc에 너무 익숙하지 않았기 때문에 어떤 도움을 주셔서 감사합니다! 그래서 여기내 작업이 나를 인덱스보기로 리디렉션하지 않습니다.
는 myModels
-CategoryID
가
CategoriesLanguages에게
ID (자동 증가)
,536을 -DateCreated 종류 인카테고리 ID
내가) (내 색인에서보기를 추가 버튼을 클릭하면
설명
기본적으로
제목의 LanguageID - 나는 AddCategory에 단지 새로운 추가() 액션을 리디렉션 해요 Categories 테이블에 레코드하고 나에게 사용자가 CategoriesLanguages 테이블 에 대한 데이터를 채울 수있는 텍스트 상자와 버튼이있는 뷰를 반환합니다. 버튼을 클릭하면 AddCategoriesLanguages () 액션에 대한 AJAX 요청을 만들고 모든 것이 괜찮습니다. 데이터베이스의 레코드지만 결국 내가 말할 때 RedirectToAction ("인덱스") 아무것도 일어나지 않습니다. 여기
여기public class CategoryViewModel
{
public List<Language> lstLanguages { get; set; }
public List<CategoryLanguages> lstCategoryLanguages { get; set; }
public CategoryLanguages categoryToEdit { get; set; }
private readonly ICategoryRepository catRep;
private readonly ILanguageRepository lanRep;
private readonly ICategoryLanguageRepository catlanRep;
public CategoryViewModel()
: this(new CategoryRepository(),new LanguageRepository(),new CategoryLanguageRepository())
{
}
public CategoryViewModel(ICategoryRepository catRep, ILanguageRepository lanRep, ICategoryLanguageRepository catlanRep)
{
this.catRep = catRep;
this.lanRep = lanRep;
this.catlanRep = catlanRep;
}
public void AddNewCategory()
{
lstLanguages = lanRep.GetAllAvailableLanguages();
newCategoryID = catRep.AddCategory();
}
public void AddCategoriesLanguages(int catID, int lanID, string title, string shortDescription, string description)
{
catlanRep.AddCategoryLanguage(catID, lanID, title, shortDescription, description);
}
이
public class CategoryController : Controller
{
public ActionResult Index()
{
CategoryViewModel ob = new CategoryViewModel();
ob.LoadLanguages();
return View(ob);
}
public ActionResult AddCategory()
{
CategoryViewModel vm = new CategoryViewModel();
vm.AddNewCategory();
return View(vm);
}
public ActionResult AddCategoriesLanguages(int catID, int lanID, string title, string shrtDescription, string description)
{
CategoryViewModel vm = new CategoryViewModel();
vm.AddCategoriesLanguages(catID, lanID, title, shrtDescription, description);
return RedirectToAction("Index");
}
다음
내보기 AddCategory.cshtml
@model Onion.Web.ViewModels.CategoryViewModel
<script>
$(document).ready(function() {
$('#btnAdd').click(function() {
var variab = 2;
$.ajax({
type: "GET",
url: '@Url.Action("AddCategoriesLanguages")' + '?catID=' [email protected] +'&lanID=' + $("#ddlLanguages").val() + '&title=' + $('#txbTitle').val() + '&shrtDescription=' + $('#txbShortDescription').val() + '&Description=' + $('#txbDescription').val(),
data: {}
});
});
});
</script>
<h2>AddCategory</h2>
@Html.DropDownList("Languages", new SelectList(Model.lstLanguages, "LanguageID", "Name",@HttpContext.Current.Session["langID"]),new { id = "ddlLanguages" })
<br />
<label for="txbTitle">Title:</label>
<input type="text" id="txbTitle"/>
<br />
<label for="txbShortDescription">Short Description:</label>
<input type="text" id="txbShortDescription" />
<br />
<label for="txbDescription">Description:</label>
<input type="text" id="txbDescription" />
<br />
<br />
<input type="button" id="btnAdd" value="Add" />
당신이 ajax.call 성공에 페이지를 다시로드 시도 할 수 있습니다보기에이 같은 시도 – Miller