ورود

View Full Version : سوال: تبدیل کد به mvc



parsdarab
دوشنبه 31 خرداد 1395, 11:25 صبح
سلام دوستان در لینک زیر یه ویرایشگر انلاین وجود داره که برای مدیریت محتوا لازمش دارم.

https://www.froala.com/wysiwyg-editor/docs/server-integrations/php-image-manager

مشکل اینجاست زبان php هست و میخام اونو به C#‎‎‎ تبدیل کنم



<?php
// Array of image objects to return.
$response = array();

// Image types.
$image_types = array(
"image/gif",
"image/jpeg",
"image/pjpeg",
"image/jpeg",
"image/pjpeg",
"image/png",
"image/x-png"
);

// Filenames in the uploads folder.
$fnames = scandir("uploads");

// Check if folder exists.
if ($fnames) {
// Go through all the filenames in the folder.
foreach ($fnames as $name) {
// Filename must not be a folder.
if (!is_dir($name)) {
// Check if file is an image.
if (in_array(mime_content_type(getcwd() . "/uploads/" . $name), $image_types)) {
// Build the image.
$img = new StdClass;
$img->url = "/uploads/" . $name;
$img->thumb = "/uploads/" . $name;
$img->name = $name;

// Add to the array of image.
array_push($response, $img);
}
}
}
}

// Folder does not exist, respond with a JSON to throw error.
else {
$response = new StdClass;
$response->error = "Images folder does not exist!";
}

$response = json_encode($response);

// Send response.
echo stripslashes($response);
?>



مشکل در قسمتی به وجود میاد که میخواهد مقدار برگشتی را به ویو ارسال کند نمی دونم از چه نوعی است؟

راهنمایی بفرمایید

parsdarab
چهارشنبه 02 تیر 1395, 23:44 عصر
سلام مشکل با کد زیر حل شد


public class test
{
public string url { get; set; }
public string thumb { get; set; }
}

public ActionResult LoadImageGallery(string id)
{
var dir = Server.MapPath(PathUploadImage);
//http://stackoverflow.com/questions/7487007/how-can-i-enumerate-through-a-folder-to-get-all-file-names-in-an-asp-net-mvc-web
//http://stackoverflow.com/questions/163162/can-you-call-directory-getfiles-with-multiple-filters
var files = Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories)
.Where(s => s.EndsWith(".png") || s.EndsWith(".jpg"));

List<test> p = new List<test>();
//http://stackoverflow.com/questions/12524398/directory-getfiles-how-to-get-only-filename-not-full-path
foreach (string file in files)
p.Add(new test
{
url = PathUploadImage + Path.GetFileName(file),
thumb = PathUploadImage + Path.GetFileName(file)
});

return Json(p, JsonRequestBehavior.AllowGet);
}

اینم نمونه گالری


141012