<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>fromquery vs frombody asp.net core fromquery array - TheCodeBuzz</title>
	<atom:link href="https://thecodebuzz.com/tag/fromquery-vs-frombody-asp-net-core-fromquery-array/feed/" rel="self" type="application/rss+xml" />
	<link>https://thecodebuzz.com</link>
	<description>Best Practices for Software Development</description>
	<lastBuildDate>Mon, 22 Jan 2024 03:03:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://thecodebuzz.com/wp-content/uploads/2022/11/cropped-android-chrome-512x512-1-1-51x51.jpg</url>
	<title>fromquery vs frombody asp.net core fromquery array - TheCodeBuzz</title>
	<link>https://thecodebuzz.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Pass Multiple Inputs to an HTTP GET in .NET -Guidelines</title>
		<link>https://thecodebuzz.com/how-to-pass-multiple-inputs-to-http-get-asp-net-core-guidelines/</link>
					<comments>https://thecodebuzz.com/how-to-pass-multiple-inputs-to-http-get-asp-net-core-guidelines/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 06 Mar 2021 03:48:00 +0000</pubDate>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[asp net core multiple query string parameters]]></category>
		<category><![CDATA[asp.net core fromquery complex object]]></category>
		<category><![CDATA[asp.net core query parameters]]></category>
		<category><![CDATA[c# http get request with parameters]]></category>
		<category><![CDATA[fromquery asp.net core]]></category>
		<category><![CDATA[fromquery optional]]></category>
		<category><![CDATA[fromquery vs frombody asp.net core fromquery array]]></category>
		<category><![CDATA[fromquery vs fromuri asp net core model binding list of objects]]></category>
		<category><![CDATA[Fromqueryattribute]]></category>
		<category><![CDATA[how to pass multiple parameters in get request]]></category>
		<category><![CDATA[how to pass multiple parameters in get request in restful web api c#]]></category>
		<category><![CDATA[pass multiple parameters to web api get method c#]]></category>
		<category><![CDATA[web api two get methods with same parameters]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=15323</guid>

					<description><![CDATA[<p>Pass Multiple Inputs to an HTTP GET in .NET Today in this article, we shall see a simple and basic way to Pass Multiple Inputs to an HTTP GET in .NET. ASP.NET Core API template gives you multiple ways to pass the input argument like using arguments within the route or the query. We shall [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/how-to-pass-multiple-inputs-to-http-get-asp-net-core-guidelines/">Pass Multiple Inputs to an HTTP GET in .NET -Guidelines</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">Pass Multiple Inputs to an HTTP GET in .NET</h1>



<p>Today in this article, we shall see a simple and basic way to Pass Multiple Inputs to an HTTP GET in .NET.</p>



<p></p>



<p> ASP.NET Core API template gives you multiple ways to pass the input argument like using arguments within the route or the query.</p>



<p></p>



<p></p>



<p>We shall cover below aspects in this article,</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-getting-started">Getting started</a></li><li><a href="#how-to-pass-multiple-parameters-to-a-get-method">Pass Multiple Parameters to a GET API using Query Parameters</a><ul><li><a href="#aioseo-example-1">Example 1</a></li><li><a href="#aioseo-example-2">Example 2:</a></li></ul></li><li><a href="#aioseo-example-3">Example 3:</a></li><li><a href="#passing-multiple-parameters-using-fromrouteattribute">Pass Multiple Parameters to a GET API using Inline Route Parameters</a><ul><li><a href="#aioseo-example-1">Example 1:</a></li><li><a href="#aioseo-example-2">Example 2:</a></li></ul></li><li><a href="#conclusion">Summary</a></li></ul></div>



<p></p>



<p>Above discussed approach can be used in ASP.NET API or MVC project templates as required. </p>



<p></p>



<p>It&#8217;s important to follow the proper <a href="https://www.thecodebuzz.com/restful-api-url-naming-conventions-best-practices/" target="_blank" rel="noopener" title="RESTFul API URL Naming Conventions and Best Practices">URL naming convention for REST API</a>.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-getting-started">Getting started </h2>



<p></p>



<p>Let&#8217;s create ASP.NET 6 API application,</p>



<p></p>



<figure class="wp-block-image size-large is-resized"><img fetchpriority="high" decoding="async" width="1024" height="711" src="https://www.thecodebuzz.com/wp-content/uploads/2021/04/Pass-Multiple-Parameters-to-a-GET-Method-in-ASP.NET-Core-1024x711.jpg" alt="" class="wp-image-15325" srcset="https://thecodebuzz.com/wp-content/uploads/2021/04/Pass-Multiple-Parameters-to-a-GET-Method-in-ASP.NET-Core-1024x711.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/04/Pass-Multiple-Parameters-to-a-GET-Method-in-ASP.NET-Core-300x208.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/04/Pass-Multiple-Parameters-to-a-GET-Method-in-ASP.NET-Core-768x533.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/04/Pass-Multiple-Parameters-to-a-GET-Method-in-ASP.NET-Core-1536x1067.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/04/Pass-Multiple-Parameters-to-a-GET-Method-in-ASP.NET-Core-749x520.jpg 749w, https://thecodebuzz.com/wp-content/uploads/2021/04/Pass-Multiple-Parameters-to-a-GET-Method-in-ASP.NET-Core.jpg 1728w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<p>There are multiple ways to pass multiple parameters to a method, but the following are the options mostly used for the GET method:</p>



<p></p>



<ul class="wp-block-list">
<li>Using&nbsp;<code><strong><em>FromRouteAttribute</em></strong></code></li>
</ul>



<p></p>



<ul class="wp-block-list">
<li>Using&nbsp;<code><strong><em>FromQuery</em></strong></code></li>
</ul>



<p></p>



<h2 class="wp-block-heading" id="how-to-pass-multiple-parameters-to-a-get-method">Pass Multiple Parameters to a GET API using Query Parameters</h2>



<p></p>



<h3 class="wp-block-heading" id="aioseo-example-1">Example 1</h3>



<p></p>



<pre id="block-e5723d55-4224-4192-92a6-344f427f4edb" class="wp-block-preformatted">https://localhost:44367/api/Accounts/PersonalAccounts?employeeId=123</pre>



<pre class="wp-block-preformatted">         [HttpGet]
         [Route("PersonalAccounts")]
         public async Task GetAccountDetails(int employeeId)
         {</pre>



<p></p>



<h3 class="wp-block-heading" id="aioseo-example-2"><em>Example 2</em>:</h3>



<p></p>



<pre class="wp-block-verse">https://localhost:44367/api/Accounts/PersonalAccounts?employeeId=123&amp;accountNumber=238</pre>



<p></p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="231" src="https://www.thecodebuzz.com/wp-content/uploads/2021/04/send-Multiple-Parameters-to-a-GET-Method-in-ASP.NET-Core-1024x231.jpg" alt="Pass Multiple Inputs to an HTTP GET" class="wp-image-15333" srcset="https://thecodebuzz.com/wp-content/uploads/2021/04/send-Multiple-Parameters-to-a-GET-Method-in-ASP.NET-Core-1024x231.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/04/send-Multiple-Parameters-to-a-GET-Method-in-ASP.NET-Core-300x68.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/04/send-Multiple-Parameters-to-a-GET-Method-in-ASP.NET-Core-768x173.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/04/send-Multiple-Parameters-to-a-GET-Method-in-ASP.NET-Core-1536x346.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/04/send-Multiple-Parameters-to-a-GET-Method-in-ASP.NET-Core-785x177.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/04/send-Multiple-Parameters-to-a-GET-Method-in-ASP.NET-Core.jpg 1862w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<h2 class="wp-block-heading" id="aioseo-example-3">Example 3:</h2>



<p></p>



<pre id="block-e5723d55-4224-4192-92a6-344f427f4edb" class="wp-block-preformatted">https://localhost:44367/api/Accounts/PersonalAccounts?employeeId=123&amp;accountNumber=238&amp;taxid
</pre>



<pre class="wp-block-preformatted">         [HttpGet]
         [Route("PersonalAccounts")]
         public async Task GetAccountDetails(string employeeId, int accountNumber, int taxId)
         {

         }</pre>



<p></p>



<p>So with the <a href="https://www.thecodebuzz.com/restful-api-url-naming-conventions-best-practices/" target="_blank" rel="noopener" title="RESTFul API URL Naming Conventions and Best Practices">query parameter</a>, the input sequence gets matched with corresponding input parameters at the Controller method level.</p>



<p></p>



<h2 class="wp-block-heading" id="passing-multiple-parameters-using-fromrouteattribute">Pass Multiple Parameters to a GET API using Inline Route Parameters</h2>



<p></p>



<p>In this option, the parameters are bound using the route data from the current request. </p>



<p></p>



<p>Here we make use of the attribute [FromRoute] to indicate the parameter to be picked up from the inline route parameter.</p>



<p></p>



<p>The parameter provided using [FromRoute] should exactly match the input argument from the route.</p>



<p></p>



<p></p>



<h3 class="wp-block-heading" id="aioseo-example-1">Example 1:</h3>



<p></p>



<pre id="block-7e0d0589-d7a2-4428-915b-aace9cba9662" class="wp-block-preformatted">https://localhost:44367/api/Accounts/PersonalAccounts/203050
</pre>



<pre class="wp-block-preformatted">         [HttpGet]
         [Route("CheckingAccounts")]
         public async Task GetChkAccountDetails(int employeeId)
         {
         }</pre>



<p></p>



<h3 class="wp-block-heading" id="aioseo-example-2">Example 2:</h3>



<p></p>



<pre class="wp-block-preformatted">https://localhost:44367/api/Accounts/CheckingAccounts/2040/123123</pre>



<p></p>



<pre class="wp-block-preformatted">         [HttpGet]
         [Route("CheckingAccounts/{employeeId}/{accountNumber}")]
         public async Task GetChkAccountDetails([FromRoute] int employeeId, [FromRoute] int accountNumber)
         {
         }</pre>



<p></p>



<p>Please note that there are a few limitations on the size of input data that can be passed to the HTTP GET method as per specification. </p>



<p></p>



<p></p>



<p>Please read the below article to understand the same if interested,</p>



<p></p>



<ul class="wp-block-list">
<li><em> <a href="https://www.thecodebuzz.com/http-get-delete-request-body-guidelines/" target="_blank" rel="noopener" title="HTTP GET with Request body – Guidelines">HTTP GET with Request body – Guidelines</a></em></li>
</ul>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<h2 class="wp-block-heading" id="conclusion">Summary </h2>



<p></p>



<p>Today in this article, we learned different ways of passing multiple parameters to a GET method using  FromRouteAttribute, and FromQuery inbuilt supported annotation in ASP.NET Core.</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p>



<p></p><p>The post <a href="https://thecodebuzz.com/how-to-pass-multiple-inputs-to-http-get-asp-net-core-guidelines/">Pass Multiple Inputs to an HTTP GET in .NET -Guidelines</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/how-to-pass-multiple-inputs-to-http-get-asp-net-core-guidelines/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
