我在MVC控制器中有以下代码来上传img并将其保存在文件夹中:
library(raster)
library(rasterVis)
## Example data
r <- raster(ncol=4, nrow=2)
r[] <- sample(1:4, size=ncell(r), replace=TRUE)
r <- as.factor(r)
## Add a landcover column to the Raster Attribute Table
rat <- levels(r)[[1]]
rat[["landcover"]] <- c("land","ocean/lake", "rivers","water bodies")
levels(r) <- rat
## Plot
levelplot(r, colorkey=list(height=1), col.regions=rev(terrain.colors(4)), xlab="", ylab="")
这是我在angularjs服务中的代码:
public ActionResult UploadLogo(HttpPostedFileBase file)
{
var path = "";
if (file != null)
{
if (file.ContentLength > 0)
{
if (Path.GetExtension(file.FileName).ToLower() == ".jpg" ||
Path.GetExtension(file.FileName).ToLower() == ".png" ||
Path.GetExtension(file.FileName).ToLower() == ".gif" ||
Path.GetExtension(file.FileName).ToLower() == ".jpeg")
{
path = Server.MapPath("~/GroupApp/Content/Images/");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
path = Path.Combine(path, file.FileName);
file.SaveAs(path);
return new HttpStatusCodeResult(HttpStatusCode.OK);
}
}
}
return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ""); // :(
}
我能说什么,它的效果很好,但为什么在执行这段代码后,整个视图都在刷新?
我的角度控制器中没有任何刷新或视图更改功能。
当我对代码进行调试时,我点击了突破点:&#39; file.SaveAs(path)&#39;我注意到该页面开始重新加载后。
有人可以向我解释原因吗?那之后如何防止重新加载页面?
答案 0 :(得分:0)
我的坏。经过小小的推广后我发现了: here
答案 1 :(得分:0)
Can you remove the timeout function and access the result directly.
Like this
$http.post(controllerQuery, _file, {
transformRequest: angular.identity,
headers: { 'Content-Type': undefined },
enctype: 'multipart/form-data'
})
.then(function (result) {
deferred.resolve(result);
},
function (error) {
deferred.reject(error);
});
return deferred.promise;
};