razor

Pass js variable or inout value to razor

戏子无情 提交于 2019-12-29 07:59:33
问题 Is it possible to pass js variable or html value to razor? @{ int n = ?????; Html.RenderPartial("_AddressBookEdit", @Model.Addresses[n]); } How can I set variable n from javascript or assign it a value from a hidden field? n = $('#myvar').val()'; The above code does not work. 回答1: You are missing a fundamental understanding here. I already answered a version of this question by you, however I did not think you misunderstood this point. You cannot pass anything from javascript to razor without

Why doesn't Request.IsAjaxRequest() work in ASP.NET MVC 3?

南笙酒味 提交于 2019-12-29 07:58:42
问题 I'm creating a new project, asp.net mvc3 with Razor, and wanting to turn the LogOn into an ajax request. HTML @using (Ajax.BeginForm("LogOn", "Account", new AjaxOptions { HttpMethod="post", OnSuccess="LoginSubmitted"})) { } Controller if (Request.IsAjaxRequest()) { return Json(new { ResultMessage = "Username or password provided is incorrect"}); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } Everything else remains the same. First, looking at the

Is there a benefit to using @Url.Content(“~”)

放肆的年华 提交于 2019-12-29 07:55:15
问题 I'm new to MVC4/razor2, and I think understand the general benefit of using @Url.Content and @Url.Action - if my routing or virtual directory changes, magic-url-strings are correctly rendered. I'm looking at some legacy Javascript-with-razor code in a view that is peppered with '@Url.Content("~")' . This renders out as '/' - or, website root. Which.... would always be the case, no? Or is there some situation in which this could be rendered differently? Note: it is not ~/ - just plain ol'

View does not refresh after change

故事扮演 提交于 2019-12-29 07:26:12
问题 I am having this frustrating problem. I change text in a razor view (cshtml), Start without Debugging , refresh (Ctrl+F5) the browser but nothing happens. The strange part is that if I modify a controller's return value (say return Ok("test"); ) or an included static file (like CSS), refresh, the change is visible. The razor view only updates if I stop start and stop debugging every time. Here are things I have already tried: Made sure that Detect when file is changed outside the environment

View does not refresh after change

本秂侑毒 提交于 2019-12-29 07:26:10
问题 I am having this frustrating problem. I change text in a razor view (cshtml), Start without Debugging , refresh (Ctrl+F5) the browser but nothing happens. The strange part is that if I modify a controller's return value (say return Ok("test"); ) or an included static file (like CSS), refresh, the change is visible. The razor view only updates if I stop start and stop debugging every time. Here are things I have already tried: Made sure that Detect when file is changed outside the environment

select right menu on master page in MVC from child page

狂风中的少年 提交于 2019-12-29 07:07:48
问题 I have a couple of list items in a shared _layout.cshtm file (master page) in my MVC application. something like: <ul> <li>Home</li> <li>about</li> <li>contact</li> <li>blog</li> </ul> when the user is in a homepage, I want home li item to have class selected , like so: <li class="selected">Home</li> and so on. What is the best way to do this? In regular asp.net website, I used to have a method in master page and call that method from child page but in MVC I am not sure what to do. thanks.

select right menu on master page in MVC from child page

孤街醉人 提交于 2019-12-29 07:07:10
问题 I have a couple of list items in a shared _layout.cshtm file (master page) in my MVC application. something like: <ul> <li>Home</li> <li>about</li> <li>contact</li> <li>blog</li> </ul> when the user is in a homepage, I want home li item to have class selected , like so: <li class="selected">Home</li> and so on. What is the best way to do this? In regular asp.net website, I used to have a method in master page and call that method from child page but in MVC I am not sure what to do. thanks.

A potentially dangerous Request.Path value was detected from the client (&)

℡╲_俬逩灬. 提交于 2019-12-29 06:54:49
问题 I understand why this is happening but I need a work-around. I looked into some other questions on StackOverflow but none of them was helpful. I do not want disable input validation throughout the whole website because that is definitely dangerous. I have only one (at least for now) place where I need to disable input validation. I decorated the Action Method with [ValidateInput(false)] attribute, and I'm encoding the strings with Html.Encode. But still, I get the same error. Here's my view:

Authentication problems after publishing MVC 4 app to azure

一笑奈何 提交于 2019-12-29 06:50:33
问题 I have a basic ASP.NET MVC 4 site which I am hosting on Azure websites. The authentication is forms authentication and has not been customised from the default template. Every time I publish, when I revisit my site, it just hangs with a very long timeout (couple of minutes perhaps) before finally showing me an error message. I can recover by deleting the cookies for the site in my browser and reloading. Initially the problem was just trying to access pages that required authentication, but

How to refresh only part of the Index page in MVC 5?

戏子无情 提交于 2019-12-29 06:12:09
问题 The Index page contains two partial views. One is for the user to enter the search criteria, the other to show the results. How to update the data in the Results view only ? I'm using MVC 5 and Razor. I've seen some examples on this, mostly using ajax and jquery. I'm asking what would be the best (prefer easier) solution for this // INDEX VIEW: <div id="div_Search"> @{Html.RenderPartial("~/Views/Shared/Search.cshtml", ViewBag.Model_Search );} </div> <div id="div_Results"> @{Html.RenderPartial