ASP.Net MVC-তে Action Result এমন একটি ডাটা টাইপ যা কন্ট্রোলারের Action Method থেকে রিটার্ন করা হয় এবং ব্যবহারকারীকে ভিউ (View) বা অন্যান্য রিসোর্স প্রদর্শনের জন্য ব্যবহৃত হয়। Action Result টাইপটি বিভিন্ন ধরনের রেসপন্স ফিরিয়ে দেয়, যেমন HTML, JSON, রিডিরেক্ট, ফাইল ডাউনলোড ইত্যাদি। এটি ব্যবহারকারীর অনুরোধের উপর ভিত্তি করে বিভিন্ন রেসপন্স প্রদান করতে সাহায্য করে।
ASP.Net MVC এ Action Result-এর বেশ কয়েকটি প্রধান টাইপ রয়েছে, যেগুলি বিভিন্ন প্রকারের রেসপন্স প্রদান করে। এর মধ্যে কিছু সাধারণ Action Result টাইপের ব্যাখ্যা নিচে দেওয়া হলো:
উদাহরণ:
public ActionResult Index()
{
return View();
}
উদাহরণ:
public ActionResult RedirectToHome()
{
return Redirect("http://example.com/home");
}
উদাহরণ:
public JsonResult GetStudentData()
{
var student = new { Name = "Rahim", Age = 22 };
return Json(student, JsonRequestBehavior.AllowGet);
}
উদাহরণ:
public ActionResult LoadStudentDetails()
{
return PartialView("_StudentDetails");
}
উদাহরণ:
public ContentResult GetMessage()
{
return Content("Hello, this is a simple message.");
}
উদাহরণ:
public FileResult DownloadFile()
{
byte[] fileBytes = System.IO.File.ReadAllBytes(Server.MapPath("~/files/sample.pdf"));
return File(fileBytes, "application/pdf", "sample.pdf");
}
উদাহরণ:
public ActionResult FindStudent(int id)
{
var student = db.Students.Find(id);
if (student == null)
{
return HttpNotFound();
}
return View(student);
}
উদাহরণ:
public EmptyResult DoNothing()
{
return new EmptyResult();
}
Action Result টাইপ ব্যবহার করার মাধ্যমে ASP.Net MVC অ্যাপ্লিকেশনগুলো দ্রুত এবং সহজে বিভিন্ন ধরনের রেসপন্স জেনারেট করতে পারে। উদাহরণস্বরূপ:
এসব রিটার্ন টাইপের মাধ্যমে ASP.Net MVC অ্যাপ্লিকেশনগুলো ইন্টারেকটিভ এবং ব্যবহারকারীর চাহিদা অনুযায়ী কাজ করতে সক্ষম হয়।
Action Result একটি গুরুত্বপূর্ণ কনসেপ্ট ASP.Net MVC-তে, যা বিভিন্ন ধরনের রেসপন্স প্রদান করতে ব্যবহৃত হয়। এর মাধ্যমে ডেভেলপাররা বিভিন্ন রিটার্ন টাইপের সাহায্যে অ্যাপ্লিকেশনকে অধিক ফ্লেক্সিবল এবং ডাইনামিক করতে পারেন। Action Result টাইপের সঠিক ব্যবহার অ্যাপ্লিকেশন ডেভেলপমেন্টের ক্ষেত্রে কার্যকরী এবং আধুনিক পদ্ধতি সরবরাহ করে।
common.read_more