fix news cat and tag

This commit is contained in:
2024-08-11 17:52:23 +03:30
parent 4ffc4197aa
commit d123ce205f
9 changed files with 31 additions and 8 deletions

View File

@ -121,19 +121,42 @@ namespace WebApplication1.Controllers
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ID,title,image,link,summary,cat,tag,publishDate,userID,Content,views")] news news)
public ActionResult Create([Bind(Include = "ID,title,image,link,summary,cat,tags,publishDate,userID,Content,views")] news news, List<string> Tags, List<string> Cat)
{
if (ModelState.IsValid)
{
if (Request.Files.Count > 0)
{
setLists();
/*
string x = news.tag;
var y = news.tag[1];
*/
if (news.title != null && news.link != null && news.cat != null && news.tag != null)
if (news.title != null && news.link != null && Cat != null && Tags != null)
{
news.tag = "";
foreach (string T in Tags)
{
if (T != Tags[0])
{
news.tag += " ,";
news.tag += T;
}
else
news.tag += T;
}
news.cat = "";
foreach (string c in Cat)
{
if (c != Cat[0])
{
news.cat+= " ,";
news.cat += c;
}
else
news.cat += c;
}
var image = Request.Files[0];
if (image.ContentLength > 1024 * 1024)
{

BIN
Media/news/32wiF8mzgi.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

BIN
Media/news/5RCYg4F954.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

BIN
Media/news/DhunrFmH5e.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

BIN
Media/news/i08QfDIQ70.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

BIN
Media/news/orYf1iXWSH.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

BIN
Media/news/rQISg2NRaA.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

BIN
Media/news/zF9LapiTFm.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

View File

@ -41,7 +41,7 @@
<div class="form-group">
<label class="control-label col-md-2">category</label>
<div>
<select id="cat" name="cat" class="form-control" multiple>
<select id="cat" name="Cat" class="form-control" multiple>
@foreach (var item in ViewBag.categoryTitle)
{
<option value="@item.title">@item.title</option>
@ -54,7 +54,7 @@
<div class="form-group">
@Html.LabelFor(model => model.tag, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="tag" name="tag" class="form-control" multiple>
<select id="tag" name="Tags" class="form-control" multiple>
@foreach (var item in ViewBag.tagTitle)
{
<option value="@item.title">@item.title</option>