// Gets the value of associated with key “MyKey” from the local resource file (“~/MyPage.aspx.en.resx”) or from the default one (“~/MyPage.aspx.resx”) //The default location for resx files is App_LocalResources object keyValue = HttpContext.GetLocalResourceObject(“~/MyPage.aspx”, “MyKey”);
Category: ASP.Net MVC
How to insert space in Razor Asp.Net
@if (condition) { <text> </text> @:  }
Search text through Divs in Javascript
<table align=”center” width=”20%”> <tr> <td style=”padding-right: 10px”> <input type=”text” id=”Search” onkeyup=”myFunction()” placeholder=”Please enter a search term..” title=”Type in a name”> </td> </tr> </table> <br> <div class=”target”> This is my DIV element. </div> <div class=”target”> This is another Div element. </div> <div class=”target”> Can you find me? </div> <script> function myFunction() { var input = document.getElementById(“Search”); […]
How to use ? : if statements with Asp.Net Razor
<span class=”btn btn-@(item.Value == 1 ? “primary” : item.Value == 2 ? “warning” : “danger”)”>EVALUATE</span> Briefly, we can say that @(condition ? “the value, if the condition is true” : “the value, if the condition is false” )
How to wrap very long text in Asp.Net Razor
That will save you: <div style=”word-break: break-all;”> THEVERYVERYLOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONGTEXT </div>
Getting index value in Razor ForEach
@{int i = 0;} @foreach(var myItem in Model.Members) { <span>@i</span> @{i++;} }
Populating Javascript array with Model in ASP.Net MVC Razor
We just need to loop through the razor collection to populate the Javascript array as below: @foreach (var item in Model) { @:$(function () { @:$(“#map”).googleMap(); @:$(“#map”).addMarker({ @:coords:[@item.Latitude], @:title: `@item.City, @item.District`, @:text: `@item.Address` @:}); @:}); }
Pass model from Razor view to JavaScript
Let’s say you send a model called “MyModel” from controller to view. In Controller: … var result = new MyModel() { Id = 1, Name = “Ercan”, FavoriteTeam = “Galatasaray”, FavoriteGame = “Half Life Series” } return View(result); … and now we will send this model which comes with result to Javascript via setName function: […]
Getting Session value in Javascript & Asp.Net
<script> var mySessionValue = ‘<%= Session[“SessionName”].ToString() %>’; alert(mySessionValue); </script>
How to add placeholder to Multiple Selection DropDownList in Asp.Net MVC
@Html.ListBox( “Countries”, ViewBag.AllCountries as MultiSelectList, new { @class = “form-control”, data_placeholder = “Choose a Country…” } )
Convert List to List in one line in C#  
			
string sNumbers = “1,2,3,4,5”; var numbers = sNumbers.Split(‘,’).Select(Int32.Parse).ToList();
How to use column search in datatable when responsive is false
just add “$(“th”).show();” in the end of initComplete … , initComplete: function () { … $(“th”).show(); } , …
Checking multiple contains on one string
new[] {“,”, “/”}.Any(input.Contains) or you can use Regex Regex.IsMatch(input, @”[,/]”);
How to render HTML tags Asp.Net MVC
string myValue = “<b>Hello</b>”; @Html.Raw(HttpUtility.HtmlDecode(myValue))
How to refresh a DIV content with Javascript
To reload a section of the page, you could use jquerys load with the current url and specify the fragment you need, which would be the same element that load is called on, in our below case #myDivId function updateDivContent() { $(“#myDivId”).load(window.location.href + ” #myDivId” ); }
Creating Multiline textbox using Html.Helper function in Asp.Net MVC
@Html.TextArea(“Body”, null, new { cols = “55”, rows = “10” }) or
Passing parameters to JavaScript files
You can assign an id to the <script> element and passing the arguments as data-* attributes. The resulting <script> tag would look something like this:
How to solve ajax.reload() not working for DataTables in JS File
If you use the reload in this way then it will probably not work. table.ajax.reload();



