I work in MVC,
The solution got divided into 3 projects:
1. I do not know Bidiok what it was for - CII.API
A. It has a folder: App_Start,
B. Veterans -Areas \ HelpPage which has a lot of folders: App_Start, Controllers, ModelDescriptions, Models, SampleGeneration, Views
C. Controllers
D. Mailers
God. Models
And. Views
And all kinds of files ....
2. The project is used to link to the DB which is Models
3. The project which has all the MVC
I have a screen where I need to keep data: half of the screen is the view of the fixed content (phone, logo, etc.)
And half of the total content varies by language (name, address, etc. - any time should keep according to the language which is currently Rolodex).
I used 2 view and ajax to display the bottom - which is the save button, and the fixed part of contents also have a separate save ..
(I want to do everything by one save, but could not at the moment)
Save- button keeps data on this page and then returns to the screen of the index-
And it works fine when I'm running through the visual.
But when I bring up the server is not making the save - and returns all the site's landing page ...
The error it brings me to chrome:
(GET http://5.100.250.76/favicon.ico 500 (Internal Server Error
And in certain places: Index? Catid = 2 & cityId = 10: 971 GET http://5.100.250.76/CII.Web/Media/Get 404 (Not Found)
I compared the web.config are pretty much the same (except that everyone went to his own DB)
What else could it be?
Thank you!!
the view:
@model CII.Domain.POIs
@{
ViewBag.Title = "Edit POI";
int langId = ViewBag.LangId;
long POIId = ViewBag.POIId;
@Html.Hidden("LanguageId", langId)
List<CII.Domain.Language> langlist = (List<CII.Domain.Language>)ViewData["languages"];
}
@using (Html.BeginForm("Edit", "POI", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<input type="hidden" value=@Model.CategoryId id="CategoryId" />
<input type="hidden" value=@Model.POIs_Lang id="langId" />
<div class="form-horizontal">
<h4>POIs</h4>
<hr />
<input hidden="hidden" id="id" value=@Model.POIId />
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.POIId)
@Html.HiddenFor(model => model.LogoFileId)
@Html.HiddenFor(model => model.ImageFileId)
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
<div class="container" style="tab-size:inherit">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#menu2" >English</a></li>
<li><a data-toggle="tab" href="#menu2" >Hebrew</a></li>
<li><a data-toggle="tab" href="#menu2" >French</a></li>
<li><a data-toggle="tab" href="#menu3" >Russian</a></li>
<li><a data-toggle="tab" href="#menu3" >Spanish</a></li>
<li><a data-toggle="tab" href="#menu1" >German</a></li>
<li><a data-toggle="tab" href="#menu2" >Italian</a></li>
<li><a data-toggle="tab" href="#menu3" >Dutch</a></li>
<li><a data-toggle="tab" href="#menu3" >Chinese</a></li>
<li><a data-toggle="tab" href="#menu1" >Japanese</a></li>
<li><a data-toggle="tab" href="#menu2" >Arabic</a></li>
</ul>
</div>
}
<div id="lang"></div>
<script type="text/javascript">
function toEdidLang(langId) {
debugger;
var id = $("#id").val();
var target = "/POI/EditLang/?id=" + id + "&langId=" + langId + "&POIId=" + POIId
$.ajax({
url: target,
type: "GET",
async: true,
success: function (result) {
$("#lang").html(result);
},
})
}
</script>
the controller:
public ActionResult Edit([Bind(Include = "POIId,CategoryId,WebsiteUrl,PhoneNumber,PhoneNumber_Spa,PhoneNumber_RoomServices,PhoneNumber_Concierge,Latitude,Longitude,LogoFileId,Location,FromDate,ToDate,CityId,ChainId,Recommended,ImageFileId,HotelId,OpenDay1,EndDay1,OpenDay2,EndDay2,OpenTime1,CloseTime1,OpenTime2,CloseTime2")] POIs pois,
ICollection<POIs_Lang> poilang,
HttpPostedFileBase[] imgfiles, string[] imageids,
int[] keep)
{
if (ModelState.IsValid)
{
if (pois.POIId == 0)
{
db.POIs.Add(pois);
}
else
{
db.Entry(pois).State = EntityState.Modified;
}
POIsImage img;
if (keep!=null)
{
Guid[] removedimgs = new Guid[keep.Count()];
int r = 0;
for (var x = 0; x < keep.Length; x++)
{
if (keep[x]==0)
{
long id;
if (long.TryParse(imageids[x],out id))
{
img = db.POIsImages.Find(id);
if (img!=null)
{
db.POIsImages.Remove(img);
removedimgs[r++] = img.FileId;
db.SaveChanges();
}
}
}
}
r = 0;
for (var x = 0; x < keep.Length; x++)
{
if (keep[x] == 1)
if (imgfiles.First() != null)
{
var file = imgfiles.Where(p => p.FileName == imageids[x]).FirstOrDefault();
if (file != null && file.ContentLength > 0)
{
img = new POIsImage();
img.POIId = pois.POIId;
img.DisplayOrder = x;
img.File = Domain.MediaServices.Save(removedimgs[r++], file, db);
db.POIsImages.Add(img);
db.SaveChanges();
}
}
}
}
foreach (var cl in poilang)
{
bool exists = db.POIs_Lang.Where(d => d.POIId == pois.POIId && d.LanguageId == cl.LanguageId).Any();
cl.POIId = pois.POIId;
if (!exists)
{
if (cl.Name != null)
db.POIs_Lang.Add(cl);
}
else
db.Entry(cl).State = EntityState.Modified;
}
db.SaveChanges();
pois.Location = LocationUtils.CreateLocation(pois.Latitude, pois.Longitude);
return RedirectToAction("Index", new { catid = pois.CategoryId });
}
ViewBag.CategoryId = new SelectList(db.Categories.Select(c => new { CategoryId = c.CategoryId, Name = c.Categories_lang.FirstOrDefault().CategoryName }), "CategoryId", "Name", pois.CategoryId);
return View(pois);
}
public ActionResult EditLang(long id, int langId)
{
POIs_Lang result = db.POIs_Lang.Where(d => d.POIId == id && d.LanguageId == langId).Include(s => s.POIs).FirstOrDefault();
if (result == null)
{
result = db.POIs_Lang.Create();
result.POIId = id;
result.POIs = db.POIs.Find(id);
result.LanguageId = langId;
result.Language = db.Languages.Where(l => l.LanguageId == langId).First();
}
return View(result);
}
[HttpPost]
public ActionResult EditLang(POIs_Lang pois, long POIId)
{
POIs data = db.POIs.Find(pois.POIId);
if (ModelState.IsValid)
{
bool exists = db.POIs_Lang.Where(d => d.POIId == POIId && d.LanguageId == pois.LanguageId).Any();
if (!exists)
db.POIs_Lang.Add(pois);
else
db.Entry(pois).State = EntityState.Modified;
if (pois.Name == null)
pois.Name = "";
if (pois.Address == null)
pois.Address = "";
if (Request.Files["attachment"] != null && Request.Files["attachment"].ContentLength > 0)
pois.File = Domain.MediaServices.Save(pois.AttachementId, Request.Files["attachment"], db);
if (Request.Files["coupon"] != null && Request.Files["coupon"].ContentLength > 0)
pois.File1 = Domain.MediaServices.Save(pois.CouponAttachementId, Request.Files["coupon"], db);
db.SaveChanges();
return RedirectToAction("Edit", new { id = POIId, catid = data.CategoryId, langId = pois.LanguageId });
}
return View(data);
}
the view "poi_lang"
@model CII.Domain.POIs_Lang
@{
ViewBag.Title = "Edit POI localized data";
}
@using (Html.BeginForm("EditLang", "POI", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.POIId)
@Html.HiddenFor(model => model.LanguageId)
@Html.HiddenFor(model => model.AttachementId)
@Html.HiddenFor(model => model.CouponAttachementId)
</div>
<table style="width:100%;">
<tr>
<td>
@if (Model != null && Model.AttachementId.HasValue)
{
<div class="form-group">
<label class="control-label col-md-2">Attachment</label>
<a class="col-md-10" href="@Url.RouteUrl("Media", new {id=Model.AttachementId})" target="_blank">View Attachment</a>
<a class="col-md-10" href="#" >Delete Attachment</a>
</div> }
<div class="form-group">
<label class="control-label col-md-2">Upload a new Attachment </label>
<div class="col-md-10">
<input type="file" id="attachment" class="form-control" name="attachment" />
@if (Model != null && Model.AttachementId.HasValue)
{
<p class="help-block">The old attachment will be replaced !</p>
}
</div>
</div>
@if (Model != null && Model.CouponAttachementId.HasValue)
{
<div class="form-group">
<label class="control-label col-md-2">Coupon</label>
<a class="col-md-10" href="@Url.RouteUrl("Media", new {id=Model.CouponAttachementId})" target="_blank">View Coupon</a>
<a class="col-md-10" href="#" >Delete Coupon</a>
</div> }
<div class="form-group">
<label class="control-label col-md-2">Upload a new Coupon </label>
<div class="col-md-10">
<input type="file" id="coupon" class="form-control" name="coupon" />
@if (Model != null && Model.CouponAttachementId.HasValue)
{
<p class="help-block">The old coupon will be replaced !</p>
}
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</td>
</tr>
</table>
}
@*<div>
@Html.ActionLink("Back to POI List", "Index", new { catid = Model.POIs.CategoryId })
</div>*@