I am new at C#, but i work in PHP, i need help for some equivalent PHP code to C# here is my code
if(isset($_GET['something'] == 'today')) {
$test = $_GET['something'];
} else {
$test = '';
}
How is possible to write that in C#?
I am new at C#, but i work in PHP, i need help for some equivalent PHP code to C# here is my code
if(isset($_GET['something'] == 'today')) {
$test = $_GET['something'];
} else {
$test = '';
}
How is possible to write that in C#?
Request.QueryString is equivalent to PHP's $_GET in C#. The QueryString collection retrieves the values of the variables in the HTTP query string.
string test = Request.QueryString["something"];
if (test == "today")
{
// we've got test logic
}
else
{
test = string.Empty;
}
$_GET in php is just server side variable.
In ASP.NET MVC you have 3 rigth places where you can store and get this variables:
ViewData - Dictiorary
ViewData.Model - Strongly Typed and the most right way
ViewBag - Dynamic type storrage.
Also, you can get this params from HttpContext.Request.QueryString like this:
HttpContext.Request.QueryString["something"]
But you should never do it in ASP.NET MVC.
ASP.NET MVC just doesn't work like this, if you have to write such a if-clause in ASP.NET MVC you don't understand it.
Basically, you would have some "action" like public ActionResult Index(string something == "today") { ... } where you can easily check the variable etc. it will be automatically fetched from your "routes" and http request context.
There are many good learning resources at http://www.asp.net/mvc like free Learning Videos from Pluralsight.