FAQ Database Discussion Community


ASP.NET MVC TextArea doesn't respect row parameters

c#,html,asp.net-mvc,razor
I have the following TextArea which contains formatted XML: @Html.TextArea("ConfigXmlView", System.Xml.Linq.XDocument.Parse(Model.IdentifiFIConfiguration.ConfigXml).ToString(), 20, 50, null) The row parameter (20 in this case) seems to not affect the actual height of the text area at all. What could the problem be? And is there a way to automatically set the height of...

How to assign C# variable to CSS class variable in ASP.NET MVC ActionLink

c#,css,asp.net-mvc,razor,dynamic-css
In the ActionLink code below, how can I assign a C# string variable to @class in the view in ASP.NET MVC 5? @Html.ActionLink("Manage List", "Index", new { @class = "DynamicClassName" }); I want to replace the static string @class = "DynamicClassName" with something dynamic, similar to @class = @myChangingColorClass //...

Cannot access conditional Razor variable as href

c#,asp.net-mvc,razor
I have a razor view that generates a url based on some items returned by the model. When I create a url variable without any if statements, the url variable can be found and used as an href. However, when I have this code (using if statements) it says: "The...

Escaping quotes in Newtonsoft JSON

c#,asp.net-mvc,razor,json.net
I've an object: public class Test { public string Prop1 { get; set; } } I'd like to serialize it to json in a view, so in my cshtml: <script type="text/javascript"> var myJson = JSON.parse([email protected](JsonConvert.Serialize(Model.MyTest))'); </script> It works, until Prop1 contains quotes, because it gets rendered as: var myJson =...

How do I convert an array from the ViewBag to a JScript array using Razor Syntax? [duplicate]

javascript,c#,arrays,asp.net-mvc,razor
This question already has an answer here: How to return Json object from MVC controller to view 3 answers I am trying to re-code the following razor syntax to be workable code and am stuck: var ServiceIndex = @ViewBag.ServiceID ; var ServiceName = @ViewBag.ServiceName ; var ServiceNotes = @ViewBag.ServiceNotes...

Using models correctly in partial razor views

c#,asp.net-mvc,razor
I have the following controller: public class WelcomeController { private IWelcomeService _service; public WelcomeController(IWelcomeService service) { _service = service; } public override ActionResult Index() { WelcomeIndexViewModel viewModel = new WelcomeIndexViewModel(); viewModel.LatestNewsArticles = _service.GetLatestNewsArticles(); return View(viewModel); } } And the following is the view model: public class WelcomeIndexViewModel { public IEnumerable<LatestNewsArticle>...

Set var in foreach to use later

c#,razor
I'm trying to set a value in a foreach but i get the error that it dosent exist in the current contect. Here is my code; @{ string sUsr = System.Web.HttpContext.Current.Request.ServerVariables["AUTH_USER"].ToLower(); var db = Database.Open("SQLServerConnectionString"); var selectUser = "SELECT * FROM USERS WHERE username = " + @sUsr; } @foreach...

MVC - Should I avoid to import more namespaces in view

asp.net-mvc,performance,razor,using-directives
I know some of you guys would consider it an unrelated question but, It's an important question for an MVC developer when you making it certain to make your application efficient and speedy. As you know that we can import a namespace into a view using 'using' clause. My question...

Kendo UI ASP.NET MVC ListView fails when trying to add or edit items

c#,asp.net-mvc,listview,razor,kendo-ui
I'm struggling to set up a ListView which allows me to add new records and to update existing ones. Loading the items for the list works like a charm. Also showing the only relevant information Id and Line works perfectly. Two problems: 1. Adding a new item to the list:...

Render different tables in a view based on years

c#,asp.net-mvc,html5,razor
I am trying to make a view that renders different html tables for different years. The model used for the view is this: public class VisualizzaFattureViewModel { public FileInfo FatturaFile { get; set; } public int Year { get; set; } } And this is the controller action: public ActionResult...

Format a multi-result single Json value

javascript,jquery,json,asp.net-mvc,razor
I have a change/getJson function that looks like this: $('#CountryId').change(function () { $.getJSON([email protected]("StateList", "Manage")', {id: $('#CountryId').val()}, function (data) { var items = '<option value="">Select a State</option>'; $.each(data.List, function (i, state) { items += "<option value='" + state.Value + "'>" + state.Text + "</option>"; }); $('#StateId').html(items); //Fail //console.log(">>>>" + data.LatLng.Latitude); //$('#Latitude').val(data.LatLng.Latitude);...

Jquery: Change contents of