嗨,我的文章模型有CategoryModel和TagModel列表。在Java腳本中,我可以發送文章標題,類別,CoverImageUrl和藝術內容。但如何發送標籤與我的功能?在這裏我的源代碼,如:如何發送數據到控制器像模型列表模型AngularJs
NewArticle查看:
@model projectCoderWho.Model.Model.ArticleModel
@{
ViewBag.Title = "NewArticle";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h4>Yeni Makale Yaz</h4>
<span class="alert-success">Makale Başlığı</span>
<br />
<input type="text" id="Header" name="Header" class="form-control" placeholder="Makale Bağlığınız..." required />
<br />
<br />
<span class="alert-success">Cover Img Url</span>
<br />
<input type="text" id="CoverImageUrl" name="CoverImageUrl" class="form-control" placeholder="Makaleniz için bir görsel..." required />
<br />
<br />
<span class="alert-success">Kategori</span>
<br />
<select class="form-control" id="Category" name="Category">
<option data-ng-repeat="cat in Categories" value="{{cat.Id}}">{{cat.CategoryName}}</option>
</select>
<br />
<br />
<span class="alert-success">İcerik</span>
<br />
<textarea id="ArtContent" name="ArtContent" placeholder="İçeriği giriniz..." cols="150" rows="10" class="form-control" style="resize:vertical" required></textarea>
<br />
<input type="text" id="Tag" name="Tag" class="form-control" placeholder="Makalenize uygun taglari yazınız...(Virgül ile ayırınız)" required />
<br />
<br />
<div class="widget categories" style="padding:0px">
<ul>
<li><a class="form-control" data-ng-click="writeNewArticle()" style="text-align:center">Makale Oluştur</a></li>
</ul>
</div>
blogController.js(writeArticle段):
$scope.writeNewArticle = function() {
$scope.NewArticle.Header = document.getElementById("Header").value;
$scope.NewArticle.ArtContent = CKEDITOR.instances.ArtContent.getData();
$scope.NewArticle.CoverImageUrl = document.getElementById("CoverImageUrl").value;
$scope.NewArticle.Category.Id = document.getElementById("Category").value;
var tags = document.getElementById("Tag").value;
ArticleApi.writeArticle($scope.NewArticle)
.success(function() {
alert("bok oldu")
})
};
articleApiService.js:
angular.module('BlogAppModule')
.factory('ArticleApi', function CategoryApiFactory($http) {
return {
all: function() {
return $http({ method: "GET", url: "Buraya Article Api gelecek" });
},
writeArticle: function (NewArticle) {
return $http({ method: "POST", url: "/Article/NewArticle", data: NewArticle })
}
}
});
個
而且ArticleController.cs(NewArticle段):
[HttpPost]
public ActionResult NewArticle(ArticleModel NewArticle)
{
if (NewArticle != null)
{
//Do something like add to database...
}
return RedirectToAction("Index", "Home");
}
我ArticleModel像這樣:
public class ArticleModel
{
public virtual int Id { get; set; }
public virtual string Header { get; set; }
public virtual string ArtContent { get; set; }
public virtual DateTime PublishDate { get; set; }
public virtual UserModel Author { get; set; }
public virtual IList<CommentModel> Comments { get; set; }
public virtual CategoryModel Category { get; set; }
public virtual string CoverImageUrl { get; set; }
public virtual DateTime EditDate { get; set; }
public virtual UserModel EditedBy { get; set; }
public virtual IList<TagModel> Tags { get; set; }
public virtual int Views { get; set; }
public virtual bool IsActive { get; set; }
public ArticleModel()
{
Comments = new List<CommentModel>();
Tags = new List<TagModel>();
}
}
正如我告訴我能趕上別人,但我不能添加標籤到文章的模型。我該怎麼辦??
謝謝你的建議我的朋友。我是angularJs的新手,剛剛學習了一些我相信的東西。我也會尋找你的建議。在我使用你的代碼示例之後,我會寫結果。而我的項目如此混雜,我知道'因爲我不能使用API進行登錄操作,另一方面,我的項目不僅適用於博客。將有用戶的自由職業者和他們的通信信息。所以,事實上我的想法對於我認爲以AngularJs開始而言是複雜的。 – CoderWho