Saturday, March 25, 2023

How to set value in a input hidden field by using model class in ASP.NET MVC?

You can do it by using your model class property into hidden field.


Step1: Include your model class in your cshtml view page

@model <YourApplicationName>.Models.<YourModelClassName>

Step2: By using model class property set it to value attribute of your hidden field

<input type="hidden" value="@Model.<YourModelClassPropertyName>" />

Demo:

Step1: Let's suppose we have a model class "Product" with some properties as given below:


Step2: Now, we have to pass our model class object to it's view page. We can pass it from an action method which will be available in a controller class. Here in this example, I'm creating a Product class object in HomeController's Index method and passing it to view page.


Step3: Now we have to access this class object on our view page. For that we can give a reference of our model class at the top of view page. Also, by using model class property, we are setting the ProductId of the referenced object into hidden field's value attribute.


Step4: 
Now we can see the output. The referenced object's ProductId is visible in input field when we checked by inspecting element in browser.


What are the necessary skills a .NET developer should have?

There are many skills a .NET developer should have to become a good developer. A developer should be good in communication skill, a good problem solver, technical proficient, hard worker and quick learner.

If we talk only about technical skills then he should have below skills.

Essentials skills:

  • .NET Framework - Basic Knowledge
  • C# Programming Language - For writing code
  • Windows Forms - For building desktop applications
  • ASP. NET MVC - For building web applications
  • ASP. NET Web API - For building REST APIs
  • HTMT, CSS, JavaScript & Bootstrap - Client-side technology for building web interfaces
  • SQL Server - for building databases

Good to have skills:

  • LINQ
  • Entity Framework
  • Azure
  • Postman
  • GitHub

How to know .NET Framework version of your project in Visual Studio?

 

Step1: Go to Solution Explorer of your project and right click on it. Once you will done a property window will open.

Step2: In property window go to last and click on "Properties" option. Once you will done a window will open.


Step3: In newly opened window you will see Application tab. Here, under General section you can find your project target .NET Framework.


Saturday, March 18, 2023

C# Basic Quiz-2

C# Quiz

1. .Net CLR is equivalent to?

2. What is CLR in C#?

3. What does the CLR in C# do?

4. SOAP in C# stands for ___.

5. "Garbage collection automatically reclaims memory occupied by unreachable unused objects." – This statement is true or false in C#?

6. Which symbols are used to mark the beginning and end of a code block?

7. Every C# statement is terminated by ___.

8. Is C# programming language a case-sensitive?

9. In C#, a single-line comment starts with ___.

10. In C#, the multi-line comments placed within the ___.

How to Crack Technical Interview – A newbie fresher?

How to Crack Technical Interview – A newbie fresher?

It’s very simple. You have to be technically sound to crack it. But wait to become a technically sound is not an easy task. You required to be put lots of effort and hard work to become a technical sound person.

The level of questions will depend upon your experience. If you are a fresher then it could be easy but if you are experienced then it could be a level up.

Tips for Fresher:

If you are a fresher then to clear this interview and get a job could be very easy for you. You have to be clear with some of the technical concepts which are generally common in every technical interview process. These are below some concepts which you have to be prepared:

1. Object Oriented Programming (OOPs) Concept - You have to be prepared with below OOPs concept. In every technical interview I faced, they asked me questions from these concepts. Questions could be simply ‘tell me about what is <any below topics>’ or they could ask ‘tell me difference between <any below topic1> and <any below topic2>’. A question that I always faced in almost every technical interview is that ‘what is difference between abstraction and encapsulation?’

  • Objects
  • Classes
  • Abstraction
  •  Inheritance
  •  Polymorphism
  •  Encapsulation

Tips: A suggestion I would like to give here is that while you are preparing for these topics, prepare a real life example as well for each topics. When interviewer asks for the topic then after explaining the definition, explain the same with your real life example.

For example, if they ask you ‘what is abstraction in oops?’ then you can explain this by below answer.

‘An abstraction is a process of hiding the internal data and implementation from the outer world. For example, in an ATM machine, we know how to perform operations like cash withdrawal, money transfer...etc but we really don't know how internally these operations work in ATM machine.’

2. Programming/Coding – For this, you should have knowledge in at least one of the programming language like C, C++, C# or Java. They could ask you to make a given program in any of the selected programming language. Questions are generally asked for checking your problem solving skills. Some the popular programming questions are as below.

  •  Swap two numbers with/without using a third variable.
  • Check whether a number is even or odd.
  • Check if the given number is prime.
  • Program to reverse a string.
  • Check if a string is palindrome.
  • Find the factorial of an integer
  • Program to print a Fibonacci series.
  • Print the total occurrences of a character in a given string.

3. Data Structure & Algorithms – In every technical interview, an interviewer always asks questions related to data structure & algorithms. It is important because when you will develop any project you would be required knowledge of these concepts. These are below some of the topics you have to prepare.

  • Array
  •  List
  •  Linked List
  • Stacks & Queues
  • Heap & Hashing
  •  Dictionary
  • Searching algorithms – Linear &  Binary search
  • Sorting algorithms – Bubble, Merge & Heap sort algorithms

4.  Sql Fundamentals

SQL is another important area to be prepared for clearing technical interview because most of the questions are also asked from this section. Below are the most important areas you have to be cover.

  •  DDL basics - create, drop, truncate, alter
  • DML basics - select, delete, update, insert
  • Keys - primary key, foreign key, unique key, composite key, candidate key
  • Conditional statements - case, if
  • Filter clause - where
  • Joins - inner join, left join, right join, full join
  • Views
  • Triggers
  • Stored procedures
  • Functions

5. Web technology fundamentals – You should also have a basic understanding about below topics

  • html
  •  http
  •  client- server architecture
  • Java script concepts- element selectors (id, class, tags), DOM manipulation operations

Last but not least another most important thing is that you have to practice questions which are previously asked.

I would like to have your feedback. If you have any question, comments or suggestions you can comment below or can email me on my email id.

Thank you for reading this article.


Friday, March 10, 2023

C# Basic Quiz-1

C# Quiz

If you want to test your basic C# skill then please attempt this quiz. It has total 10 objective type questions.

1. Who developed C# programming language?

2. C# runs on top of ___

3. Which type of application(s) can be developed by using C# programming language?

4. Is C# an object-oriented programming language?

5. Is C++ an alias of C#?

6. What is the extension of a C# language class file?

7. Who is the founder of C# programming language?

8. Is C# a type safe programming language?

9. Is C# a structured programming language?

10. CLR stands for ___

How to deploy ASP.NET Core Web API in Azure App Service

 

How to deploy ASP.NET Core Web API in Azure App Service

In this article, I am going to discuss how to deploy ASP.NET Core Web API application in Azure App Service. Here, we will discuss about below points:

  • How to create App Service in Azure?
  • How to deploy ASP.NET Core Web API in Azure App Service?

How to create App Service in Azure?

Let me first give a brief introduction of Azure App Service. Azure App Service is an HTTP-based service for hosting web applications, REST APIs, and mobile back ends. We can used it to deploy applications built in .NET, .NET Core, Java, Ruby, Node.js, PHP, or Python. It is platform as a service provided by the Microsoft. We don't need to have worry about setup things on machine, because everything is made ready by Microsoft itself.

Based on the technology we have used to build application we have to configure that on creation of App Service. We will do it in this article.

If you haven't seen my previous article then please go through that once because we are going to use the same application for deployment.

Step1: Login to Azure Portal

Step2: Search for App Services in top search bar and click on App Services under Services section


Step3: Click on Create button in App Services page


Step4:

Select your Subscription from available options in dropdown.

Select a Resource Group from available resource groups or Create New.

Provide a unique domain name for your Web API. For this demo I have given name webapidemo1990

Select Code radio button under Publish section


From Runtime stack dropdown select .NET 6(LTS). We are selecting this because we developed ASP.NET Core Web API in .NET 6. Based on your application technology and version you can select the relevant option. On selection of .NET 6(LTS), it will automatically select Windows operating system.

From Windows Plan section click on Create new button and provide a name then select Free F1 (Shared infrastructure) option.

Keep the rest of settings as it is.

Now either you can click on Next : Deployment> button or directly can click on Review + create button


Once you done this, Azure will create App Service for you and on successful creation below screen will be shown:



How to deploy ASP.NET Core Web API in Azure App Service?

Step1:  Go to your ASP.NET Core Web API project and right click on your project solution file name in Solution Explorer.


Step2:  Click on Publish from available options.

Step3:  Select Azure option from publish window and click on Next button.


Step4:  Select Azure App Service option from publish window and click on Next button.


Step5:  It will ask to login on Azure if you haven’t login before.  After login select the App Service from resource group which you had created. Finally click on Finish button.


Step6:  Click on Publish button. It will publish all code to Azure App Service. Once you got Publish succeeded message you can check it via directly browsing Web API url in browser or through any rest client tools like postman.


Step7:  If you have read my previous article you already know we were accessing Web API methods by using below URLs.

http://localhost:xxxxx/xyz/{ControllerName}/{ActionName}

But now these methods will be access by below url.

https://webapidemo1990.azurewebsites.net/xyz/{ControllerName}/{ActionName}

As per our Web API, below are the URLs for methods we created.

https://webapidemo1990.azurewebsites.net/xyz/test/get

https://webapidemo1990.azurewebsites.net/xyz/test/customname


You can also verify response by calling Web API methods through postman as below:

Here, in this article, I try to explain how to deploy ASP.NET Core Web API in Azure App Service with Examples. I hope this article will help you with your need.

I would like to have your feedback. If you have any question, comments or suggestions you can comment below or can email me on my email id.

Thank you for reading this article.

Saturday, March 4, 2023

How To Create Custom Method Names in ASP.NET Core Web API

Custom Method Names in ASP.NET Core Web API

Overview:

If you want to know how to create Custom Method Names in ASP.NET Core Web API or how to use multiple same signatures GET methods in ASP.NET Core Web API, then article is for you. Here, you will learn about which of the default method names are allowed in ASP.NET Core Web API for GET and how can we create our Custom Method Names.

Introduction:

In this article, I am going to discuss how to create Custom Method Names in ASP.NET Core Web API applications. Here, we will discuss about below points.

  • Understanding the Default Convention used by ASP.NET Core Web API.
  • How to create Custom Method Names in ASP.NET Core Web API?
  • How to create custom URL in ASP.NET Core Web API?


Understanding the Default Convention used by ASP.NET Core Web API.

Let’s understand the default convention used by ASP.NET Core Web API to map the HTTP verbs GET, PUT, POST, and DELETE to methods on a controller with an example. By default, the HTTP verb GET is mapped to a method in a controller that has the name Get().

In the following TestController, the method name is Get() so by default convention, this is mapped to the HTTP verb GET. Even if we rename it to GetStatus() or GetXYZ() or CustomName() it will still be mapped to the HTTP verb GET. The word Get is case-insensitive. It can be lowercase, uppercase, or a mix of both.

Default Method Name:

GET Custom Method Name:

Output in above both cases:

These methods are accessible by URL /test because in Route attribute the controller name is passed as a parameter.

Now let’s keep both get methods in “TestController


If we will run this application and try to access URL /test, the GET request gets failed with ambiguity error message. It is because of WebAPI is not able to differentiate which GET methods needs to be called.


Now the problem is how can we access these two methods.

First, let’s see the default implementation of the Route class which is present at the top of controller name as an attribute.


The default route specifies the URL route as domain Name Followed by controller name. In our example, it will be http://localhost:xxxxx/test where “test” is the controller name.

How to create Custom Method Names in ASP.NET Core Web API?

To implement Custom Method Names in ASP.NET Core Web API, let’s first change the default implementation of the Route class as shown below where we include the action name as part of the route.

Now make a request with the same URL /test it will give us the following error


So change the URL as we need to include the action name in the URL as we do the changes in the Route attribute.

/test/Get
/test/CustomName

That’s it. We have successfully implemented Custom Method Names in ASP.NET Core Web API. Now you will get the response as expected.


That’s it. We have successfully implemented Custom Method Names in ASP.NET Core Web API. Now you will get the response as expected. You can add as many as custom methods with same signature and it will work successfully.

How to create custom URL in ASP.NET Core Web API?

Currently we are accessing the Web API methods with this URL format http://localhost:xxxxx/{ControllerName}/{ActionName}

If we want to add something more in URL before the controller name then this also possible. For this, we have to modify Route attribute like below. Instead of xyz you can put anything.


Now, the new URL format for accessing Web API methods will be like below:

http://localhost:xxxxx/xyz/{ControllerName}/{ActionName}


In the next article, I am going to discuss Hosting ASP.NET Core Web API in Azure App Services. Here, in this article, I try to explain creating Custom Method Names in ASP.NET Core Web API with Examples. I hope this article will help you with your need. I would like to have your feedback. Please post your feedback, question, or comments about this article.

I would like to have your feedback. If you have any question, comments or suggestions you can comment below or can email me on my email id.

Thank you for reading this article and by giving your time.

Will it be possible to live on Mars, as Elon Musk has said?

Elon Musk has expressed his ambition to establish a human presence on Mars in the future. While living on Mars is a long-term goal for Space...