(#5) What is Controller in MVC | Controllers in MVC 5 | MVC Tutorial for Beginners in .net c#
Вставка
- Опубліковано 28 вер 2024
- MVC Tutorial: What is controller in MVC?
We will start this video from What is controller in MVC? Controllers are the main building blocks of any mvc 5 application. We can not imagine any mvc application without controller.
This video will cover lots of thins about controllers in mvc.
First we will learn what is controller so that we will be familiar about basics of mvc controller. Then we will learn how to add a new controller (empty or with read-write action methods). This will give us a new controller in our application. Inside a controller there are multiple public methods. These methods are called as Action methods. Action methods are responsible for returning different types of action results from controller.
We will also learn how can we pass parameters from browser (client) to controller (server) with the help of query string.
We will start by passing 1 parameter and then we will pass multiple parameters to controller.
Timestamp -
Objective of this video 00:16
What is controller in mvc 01:23
What is the use/role of controller 04:34
Definition of controller 08:07
How to create/ add a new controller 09:23
What is Action Method in mvc 15:50
How to call Action Method from browser 18:06
How to pass parameters in controller's Action Method 23:10
And most important - How will you decide when to create new controller and when to use the existing one 37:25
#mvctutorial #controllerinmvc #MVC
Subscribe WebGentle: goo.gl/PJr1pN
Visit Our Website: www.webgentle.com
Join WebGentle Community: www.webgentle....
Visit WebGentle Blog: www.webgentle....
For business enquiry contact: nitish.webgentle@gmail.com
Follow us on
==========
Facebook - / webgentle
Linkedin - / webgentle
Twitter - / webgentle
Popular free courses from WebGentle
=========
Jira tutorial - bit.ly/jiratuto...
Azure DevOps tutorial - bit.ly/azuredev...
.NET Core 3.0 fundamentals - bit.ly/dotnetcore3
MVC5 tutorial - bit.ly/mvcbynitish
LINQ Tutorial - bit.ly/linqbyni...
Non generic collection in C# - bit.ly/nongener...
Timestamp -
# Objective of this video 00:16
# What is controller in mvc 01:23
# What is the use/role of controller 04:34
# Definition of controller 08:07
# How to create/ add a new controller 09:23
# What is Action Method in mvc 15:50
# How to call Action Method from browser 18:06
# How to pass parameters in controller's Action Method 23:10
# And most important - How will you decide when to create new controller and when to use the existing one 37:25
#mvctutorial #controllerinmvc #MVC
Subscribe WebGentle: goo.gl/PJr1pN
Visit Our Website: www.webgentle.com
Join WebGentle Community: www.webgentle.com/community
Visit WebGentle Blog: www.webgentle.com/blogs
Thank you sir
This is amazing tutorials, get basic to advance knowledge of MVC, Thanku so much sir
correct output :
public string FullName(string first, string last)
{
if (!string.IsNullOrEmpty(first) && string.IsNullOrEmpty(last))
return "Your First Name is = " + first;
else if (string.IsNullOrEmpty(first) && !string.IsNullOrEmpty(last))
return "Last Name is = " + last;
else
return "Your First Name is = " + first + "And Last Name is = " + last;
}
public string FullName(string? firstname=null, string? lastname=null ){...} why can't we use this procedure?
@@saroshfaisalkhan3531 becoz string are reference type and nullable
You have missed another condition, if the user doesn't pass either "first" or "last".
@@saroshfaisalkhan3531 how can you predict input in run time ? you have to display only last name if there is no first name is declared. if you use this method it will still show first name =
lastname = something
Very nice explanation sir.
Thanks for helping me out. Really good tutorials.
Thanks for Teaching
Bohat shukriya bhai me institute ke sath sath extra learning apke daily tutorial dekh kr krta hn or implement b love form Pakistan ❤
Amazing Explanation
Amazing Teaching Technique Thank You Sir
Timing 27:30 jb hm url m I'd ki value 1 put kr re the to wo uske bad ridrect kaise kr ra hai ,,, mere p I'd ki value store nhi hori ,, jb m url m I'd ki value =1 dal ra hu n hit enter kr ra hu to redirect nhi hora n value bhi store nhi hori
sir jab ma visual studio ma variable k uper mouse la k ata ho tab jo value pass ke hoti ha browser sa wo show nhi hoti??
I am using visual studio 2022 professional
Very helpful video to understand
Ausome teaching sir
Awesome
very nice understanding!
Very nice..learnt a lot
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /
how to solve this error in visual studio 2019
i also have the same issue
Answer :-
//question 1 --------->>>>>>>>>>>>>>>>>>>>>>>>
public string name()
{
return "webgentle";
}
//question 2 --------->>>>>>>>>>>>>>>>>>>>>>>>
public string fullname(string firstName, string lastName)
{
if (firstName != null && lastName != null)
{
return "FIRSTNAME AND LASTNAME = " + firstName + " " + lastName;
}
else if (firstName != null)
{
return "FIRSTNAME = " + firstName;
}
else if (lastName != null)
{
return "LASTNAME = " + lastName;
}
return "not found";
}
Nice❤
Sir mere system me profile id wala output wahi de raha hai jo return me de raha tha, employee 1 profile nahi de raha hai
Hello sir, how to separate the code from controller to make controller more clean ?
Sir data Lake nahi show ho raha hai
Sir id 1 and 2 nahi aa raha hai
bro, nicely explained .....
but i am stuck in assignment you given in this lecture, because you taught us how to put nullable (int only) but what if its a string??
tell me how to make string as nullable ? i have tried this :
public string Name(string? fName=null,string? lName=null)
{
//code
}
You can assign null value directly to a string.
There is no need to use ? for string.
Thanks :)
well done bro!
Sir what if I don't have the preceding text of "controller" in my controller class name, will it still functional @s controller?
Please answer this question, this was asked in one interview.
Try it and post your answer.
What is scaffolding
Anybody got A nice job
can a get all the slides?
Thank you...sir
How to enable nullable reference
Keep posting new videos.
very nice Explaynation
Nice .. Thanks
Hey... Employe/EmployeProfile?id=1 didn't show? When I move my cursor in (int id).. Could you please let me know
I also have same issue 😢
Grt
can we have any name for controler cs file?
public class GameController : Controller
{
public String Name(String name)
{
return "Welcome to " + name;
}
public String FullName(String first, String last)
{
if (first != null && last != null)
{
return "Your First Name = " + first + " And Your last Name = " + last;
}
else if (first != null)
{
return "Your First Name = " + first;
}
else if(last != null)
{
return "Your Last Name = " + last;
}
return "What is Your Name?!";
}
}
very nice bro
public class HomeController : Controller
{
public string Index()
{
return "Hello";
}
public string FullName(string Firstname, string Lastname)
{
string name = string.Empty;
if(Firstname!=null && Lastname!=null)
{
name="Your first name is = "+ Firstname +" "+"and"+" "+ "Last Name is= " + Lastname;
}
else if(Firstname!= null && Lastname==null)
{
name = "Your First Name is="+ Firstname;
}
else if (Firstname == null && Lastname != null)
{
name = "Your last Name is=" + Lastname;
}
return name;
}
Its working but can you please tell me how can i make this code really short?
sir ap is m programming language c# use kr rhy hen?
ha
@@WebGentle instead of homecontrol.cs can we use .vb
Sir voice problem bohat slow hai☹️
is there any azure devops tutorial
Yes, Please watch here:
ua-cam.com/play/PLaFzfwmPR7_Ifxq-udm66fhReFeGOe2x_.html
public string FullName(string first = null, string last= null)
{
if (first==null && last !=null)
{
return "Your last name is : " + last;
}
else if (last == null && first !=null)
{
return "Your first name is : " + first;
}
else
{
return "Your first name is : " + first + " And last name : " + last;
}
}
public string Name(string name)
{
return "Welcome to " + name;
}
public string FullName(string first, string last)
{
if(first==null)
{
return "Your lastName is " + last;
}
else if(last==null)
{
return "Your firstName is " + first;
}
else
return "Your firstName is " + first + " and lastName is " + last;
}
🥰🥰🥰🥰
public class GameController : Controller
{
public string Name (string name)
{
return "Welcome to " + name;
}
public string FullName(string? first = "firstName" , string? last = "lastName")
{
return "Your first name is = " + first + " and last name is = " + last + "
" + " Your first name is = " + first + "
" + " Your last name is = " + last;
}
}
at 11:46 i name it webapplication3 but your is webapplication2
public class GameController : Controller
{
public string Name(string name)
{
return " Welcome to " + name;
}
public string FullName(string first, string last)
{
if (last == null)
{
return " My First Name is=" + first;
}
else if(first == null)
{
return " My Last Name is=" + last;
}
else
{
return " My First Name is =" + first + " and My Last Name is =" + last;
}
}
public string Address(int? i=null, int? Dept=null)
{
if(i==null)
{
return "Student Departname is " + Dept;
}
else if(Dept==null)
{
return "Student Id = " + i;
}
else
{
return "id = " + i + "and Department = " + Dept;
}
}
localhost:8555/employee/Address?i=10
output: Student Id = 10
But,
localhost:8555/employee/Address?dept=sci
output : Student Departname is
public string Info(string? strFname = null, string? strLname = null)
{
return "First Name = " + strFname + " Last Name = " + strLname;
}
===========
Its Not work..
public string FullName(string first, string last)
{
if (!string.IsNullOrEmpty(first) && string.IsNullOrEmpty(last))
return "Your First Name is = " + first;
else if (string.IsNullOrEmpty(first) && !string.IsNullOrEmpty(last))
return "Last Name is = " + last;
else
return "Your First Name is = " + first + "And Last Name is = " + last;
}
public string FullName(string Fname,string Lname)
{
if(string.IsNullOrEmpty(Fname))
{
return "Your Last name = " + Lname;
}
else if(string.IsNullOrEmpty(Lname))
{
return "Your First name = " + Fname;
}
else
{
return "Your First name = " + Fname + " and Last name = " + Lname;
}
}
public class GameController : Controller
{
// GET: Game
public string Name(string name)
{
return "Well come to " + name;
}
public string Fullname(string fname, string lname)
{
string html;
if (! String.IsNullOrEmpty(fname) && !String.IsNullOrEmpty(lname))
{
html = "Your firstname : "+fname+" And lastname :"+lname;
}
else if (!String.IsNullOrEmpty(fname))
{
html = "Your firstname : " + fname;
}
else if(!String.IsNullOrEmpty(lname))
{
html = "lastname :" + lname;
}
else
{
html = " no data found";
}
return html;
}
}
public string EmployeeName(string firstname="", string lastname="")
{
if (firstname.Length>1 && lastname.Length==0)
{
return "your firstname is " + firstname;
}else if (lastname.Length > 1 && firstname.Length==0)
{
return "your lastname is " + lastname;
}
else
{
return "your firstname is " + firstname + " your last name is " + lastname;
}
}
EXCUSE ME SIR
public string Name(string name)
{
if(name== "RajAppStore")
{
return "Welcome to RajAppStore";
}
else
{
return "No record found";
}
}
public string FullName(string firstname, string lastname)
{
if(firstname!=null && lastname!=null)
{
return "Your First Name is = " + firstname + " Your Last Name is = " + lastname;
}
else if(firstname != null)
{
return "Your First Name is = " + firstname;
}
else
{
return " Your Last Name is = " + lastname;
}
}
voice very slow
please sir check my question is right
// your first questions
public string Name(string Fname)
{
return " welcome To "fname;
}
//your secound questions
public string FullName(string Firstnam = null, string lastname = null)
{
if (Firstnam == null && lastname == null)
{
return "this is empty";
}
else if (lastname == null)
{
return " this is a first Name : " + Firstnam;
}
else if (Firstnam == null)
{
return "this is a last name :" + lastname;
}
else
{
return "firstname :" + Firstnam + "last name " + lastname;
}
}
What if the value of fname or lname is empty i.e "".
too much ads
using System.Linq;
using System.Web.Mvc;
namespace WebGentleControllers.Controllers
{
public class GameController : Controller
{
public ActionResult Index()
{
return View();
}
public string Name(string name)
{
return "Welcome to " +name;
}
public string FullName(string firstName = "", String lastName = "")
{
if (string.IsNullOrEmpty(firstName))
return "Your Lastname is = " + lastName;
else if (string.IsNullOrEmpty(lastName))
return "Your Firstname is = " + firstName;
else
return "Your Firstname is = " + firstName + " and Lastname is = " + lastName;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication6.Controllers
{
public class GameController : Controller
{
// GET: Game
public string Name(string Name)
{
return "Welcome to"+Name;
}
public string FullName(string FirstName, string LastName)
{
return "Your First Name is" + FirstName + "Last Name is" + LastName;
}
}
}
Hi Sir, is my answer correct ? see below code.
public string FullName(string first = null, string last = null)
{
string name = string.Empty;
if (first != null && last != null)
{
name = "Your First name is " + first + " and last name is " + last;
}
else if(last == null && first !=null)
{
name = "Your First name is " + first;
}
else if (last != null && first == null)
{
name = "Your Last name is " + last;
}
else
{
name = "nothing";
}
return name;
}
public string Name(string name)
{
return " Welcome To "+ name ;
}
public string FullName(string firstname,string lastname)
{
if(!string.IsNullOrEmpty(firstname) && string.IsNullOrEmpty(lastname))
{
return "Your First Name is =" + firstname;
}
else if(string.IsNullOrEmpty(firstname)&& !string.IsNullOrEmpty(lastname))
{
return "Your Last Name is =" + firstname;
}
else
return " Your First Name is = " + firstname + "and last Name is = " + lastname;
}
public string FullName(string first,string last) //NO ERROR -- IF ONLY ONE PARAMETER IS PASS
{ // (STRING)
if (first == null)
return "Your last name is " + last;
else if(last == null)
return "Your first name is " + first;
else
return "Your first name is " + first+ " and Your last name is " + last;
}
Very nicely explained.
I've been through many tutorials but didn't find better than this MVC tutorial.
Thanks!
+Ashutosh Singh Thanks.
Please like and share the video so that others can also learn.
Keep learning.
voice bhut slow hai yaar,laptop ki voice full hai phir bhi nahi aar rahi ..
public class GameController : Controller
{
public string Name(string name)
{
return "Welcome to " + name;
}
public string FullName(string first,string last)
{
if(first == null)
{
return "your last name is = " + last;
}
else if(last == null)
{
return "your first name is = " + first;
}
else
{
return "your first name is = " + first + ", your last name is = " + last;
}
}
}
Please use zoom while doing coding videos,code fonts are very small and not able to see properly
well structured and nicely explained !!
You are doing a great job. Your methodology is very genius and easily understandable.
Speak loudly
Kya tutorial hai sir maja ageya...Superb
public string Fullname(string number_1 = null, string number_2 = null)
{
if (number_1 != null && number_2 != null)
{
return "your first name is " + number_1 + " and last name is " + number_2;
}
else if (number_1 != null && number_2 == null)
{
return "your first name is " + number_1;
}
else if (number_1 == null && number_2 != null)
{
return "your first name is " + number_2;
}
else
{
return "provide atleast one argument";
}
}
Nice try but you can improve it. :)
public string Name(string name)
{
return "welcome to " + name;
}
how can make string Type Nullable or opetional?
very amazing playlist I appreciate your hard work
I add this method:
public string TestName(string firstName, string lastName)
{
return firstName+" "+lastName;
}
Even I did not pass a single parameter through URL, it does not show me the error?? how its auto nullable parameters?? I am using MVC template while creating the project - is MVC framework automatically manage it, or there is an issue with my method? please suggest.
thank you so much sir this tutorial
sir you are great.....nice explanation
Your voice look to lazy please make interactive video . content is good
Can we make the Quiz by using MVC 5 . If you have any ideas please send me the ideas.
Really great tutorial. Lots of respect for you sir. Thank You.
public string Game(String FristName, string LastName = null)
{
if (LastName == null && FristName != "")
return "Welcome To " + FristName;
else
return "Frist Name " + FristName + " And " + " Last Name " + LastName;
}
this is right or wrong ? Sir .
Very well taught 👌👍👍thankyou sir
public string FullName(string FName=null, string LName=null)
{
string name = string.Empty;
if(FName==null)
{
return "lasttname=" + LName;
}
else if(LName==null)
{
return "firstname=" + FName;
}
else
return "first name="+FName+ "and last name =" + LName;
}
Answer for the homework quiz
public string FullName(string first, string last)
{
if (first=="firstname" && string.IsNullOrEmpty(last))
{
return "Your First Name= "+first;
}
else if(last == "lastname" && string.IsNullOrEmpty(first))
{
return "Your last name= " + last;
}
else if(first == "firstname" && last=="lastname")
{
return "Your first name is = "+first+ " and last name = " + last;
}
else
{
return "plz enter a valid name";
}
}
public class GameController : Controller
{
public String Name(String name)
{
return "Welcome to " + name;
}
public String FullName(String firstName, String lastName)
{
if(firstName==null && lastName != null)
{
return "your last name is = " + lastName;
}
else if(firstName != null && lastName == null)
{
return "your first name is = " + firstName;
}
else
{
return "your first name is = " + firstName + "and last name is = " + lastName;
}
}
}
public string FullName(string First, string Last)
{
if (First == null)
{
return " Your Last Name is " + Last;
}
else if (Last == null)
{
return "Your First Name is " + First;
}
else
{
return "Your First Name is " + First + "and Your Last Name is " + Last;
}
}
Please also add subtitle for your videos ... It is very nice
dear sir empty string check krne k lie 2sra koe method he??
string.IsNullOrEmplt
Very nice explained
Sir jb main controller add kr rha hn mery pass script fonts waly kuch folder nj arhe mv. Empty main
Thankyou so much sir.
Can you provide some thoery notes of that??
Do u have slides of this series?
could u please provide it to me?please
i get IIS EXPRESS(GOOGLE CHROME ) NOT GOOGLE CHROME
sir same problem with me ,please what
to do?
Employee is not accessible after creating controller
Aapka aawaj bhaut kam aaraha he sir
Hello sir,
video time 27:41 ,
is m id ke value show ho rahe h,
mera visual studio m show nhi ho rahe h
Sir second home work is not able to solve ..please solve it sir
Thank you so much for simply great explanation