اذهب إلى المحتوى
  • 0

كيف أنشئ متحكم Controller في ASP.Net MVC5؟

Jason

السؤال

Recommended Posts

  • 0

يقوم المتحكم Controller في MVC بتعريف الصفحات Views وذلك بتحديد دالة باسم كل صفحة يتم التحكم بها باستخدام Controller 

  public ActionResult Index()
        {
            return View();
        }

لإنشاء متحكم Controller اضغط بالزر اليميني على المجلد Controllers واختر Add Controller

addController.thumb.png.68ac4791443f3829

ستلاحظ أنه تم إنشاء مجلد جديد في المجلد Views بنفس اسم المتحكم بدون كلمة Controller (سيتم فيه إنشاء الصفحات Views التي سيتم تعريفها في المتحكم)

ControllerFolder.thumb.png.95a3c158b6c24

أنشئ الصفحات التي تريدها في المجلد.

اكتب الشيفرة التالية في ملف المتحكم Controller (في المثال myTemplateController.cs)

 

ing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace InstallmentsWorld9_1_2016.Controllers
{
    public class myTemplateController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult AboutUs()
        {
            return View("AboutUs");
        }

        public ActionResult News()
        {
            return View("News");
        }

    }
}

 

تم التعديل في بواسطة Lujain
رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...