viewdata

MVC - Passing Parameters from View to Popup

不想你离开。 提交于 2019-12-11 19:16:50
问题 I'm having a problem passing parameters from my view to my popup. In my view, I have the following razor code to render an Action Link wherein when I click it, a pop-up will appear: @Html.ActionLink("[Edit Product]", "Edit", "Products", new { ProductCode = @Model.ProductCode}, new { @class = "editLink" }) I'm not quite sure if this is correct or if the part new { ProductCode = @Model.ProductCode} makes any sense (please explain to me what that part does, anybody hihi). Anyway, my pop-up code

Looping and comparing ViewData data with DropDownListFor using Jquery

别来无恙 提交于 2019-12-11 15:53:56
问题 Via controller, I am sending a ViewData to my View (.cshtml) with the name of several other ViewDatas. On the controller side, I am creding and sending this way: List<string> Names = new List<string>(); Names.Add(NameForViewBag.ToString()); ViewData["ViewDataNames2"] = Names; So, this stores all the name of the ViewDatas that I am creating. Then, and where I am struggling, is how to work with this ViewData, using Jquery, on my .cshtml side. My idea is to Get each of this ViewData[

Strongly typed master pages polymorphism - nested masterpages ignore inherit attribute

☆樱花仙子☆ 提交于 2019-12-11 07:47:54
问题 I'm currently creating a CMS system and found that the following doesn't work. I do have a work around that isn't exactly ideal and feels dirty. I'm cool with it for now and not really that interested in a different approach (but don't let that stop you answering). What I am after is some kind of explaination on why it doesn't work - is it a bug in ASP.NET MVC? It's hard to explain so I'll let my code (minus alot of fluff) do the talking... hope it makes sense! EDIT: It seems that the

Maintaining ViewBag values while posting data

北战南征 提交于 2019-12-11 00:07:13
问题 I have a logical question that needs to be answered!! Here is a scenario.. -In controller ViewBag.Name = "aaaa"; -In View @ViewBag.Name "In my controller, i have set value for ViewBag and retrieved value from ViewBag in VIew. Now in View, i have a button, which is posting some data to a HttpPost method. In HttpPost method, i have changed the values for ViewBag. So after the execution of that method, the values in the viewbag will change or not for current view??" -In HttpPost Method ViewBag

The name 'ViewData' does not exist in the current context

谁都会走 提交于 2019-12-10 18:59:36
问题 I am working over my first application over MVC3 and still kind of a newbie in it: I’m trying to success my ViewData[] over a master page because its contains a message that would be used over every page, but when I’m trying to access that it says: CS0103: The name 'ViewData' does not exist in the current context var msg = ViewData["msg"] as string; //var msg = ViewBag.msg as string; if (msg != null) { Response.Write (msg); } else if (msg == null) { Response.Write(""); } I am not sure whether

Getting User Information using SimpleMembership

回眸只為那壹抹淺笑 提交于 2019-12-10 17:03:56
问题 Still trying to get to grips to the new SimpleMembership with MVC4. I changed the model to include Forename and Surname which works fine. I want to change the information displayed when logged in so instead of using User.Identity.Name in the View I want to do something like User.Identity.Forename, what's the best way to accomplish this? 回答1: Yon can leverage @Html.RenderAction() feature available in ASP.NET MVC to display this kind of info. _Layout.cshtml View @{Html.RenderAction("UserInfo",

How to pass ViewData from Controller to my JS

让人想犯罪 __ 提交于 2019-12-08 15:25:33
I have the below scenario where I am passing data from my controller to view CONTROLLER: public ActionResult Create(string ID) { if (ID!= null) { int nid = Convert.ToInt32(ID); DataWiz NDW = new DataWiz(); ViewData["Filter"] = NDW.Filter(nid); } return View(); } VIEW (Razor): @{ var Filter = ViewData["Filter"]; } @section Create(//this is rendered in from Layout) { <script src="@Url.Content("~/Scripts/Create.js")" type="text/javascript"></script> } When I debug the View I am able to see the data in Filter but how do I get this to my JS in the document ready function. JAVASCRIPT: $(document)

asp.net mvc dropdownlist no ViewData item

大兔子大兔子 提交于 2019-12-08 09:06:33
问题 i start to study mvc, try to add dropdownlist, make construction <%= Html.DropDownList("ddl") %> but it show error There is no ViewData item of type 'IEnumerable' that has the key 'ddl' why? i use simple code, only pass name parameter, so why the error? 回答1: "There is no ViewData item of type 'IEnumerable'" It means that helper method is expecting an item of type 'IEnumerable' for e.g, List<> with an Id 'ddl' If you are trying to display a DropDownList which has items from some static source,

How to pass ViewData from Controller to my JS

只谈情不闲聊 提交于 2019-12-08 05:46:06
问题 I have the below scenario where I am passing data from my controller to view CONTROLLER: public ActionResult Create(string ID) { if (ID!= null) { int nid = Convert.ToInt32(ID); DataWiz NDW = new DataWiz(); ViewData["Filter"] = NDW.Filter(nid); } return View(); } VIEW (Razor): @{ var Filter = ViewData["Filter"]; } @section Create(//this is rendered in from Layout) { <script src="@Url.Content("~/Scripts/Create.js")" type="text/javascript"></script> } When I debug the View I am able to see the

passing viewdata to asp.net mvc masterpages

青春壹個敷衍的年華 提交于 2019-12-06 01:41:34
问题 I'm trying to pass ViewData to my asp.net mvc masterpage for an mvc usercontrol that I keep on a masterpage. For example, I created a dropdownlist of names as an mvc usercontrol and I put that in my masterpage. The problem I am running into is passing the ViewData to the masterpage. I found this article from Microsoft which has a decent solution but I was wondering if there are other "better" solutions out there. The thing I don't like about the solution in the link is that I have to change