Search Results

Search found 386 results on 16 pages for 'viewdata'.

Page 4/16 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How to return a MVC View to a $.Ajax JSON POST

    - by flascuba
    I am sending a $.Ajax POST to a MVC Controller function with parameters and returning a JasonResult successfully. What I need to happen is that the current View be returned (as if it was not a JSON request and I was returning the Viewdata). The Viewdata has been updated and the page needs to be redrawn. In short, I want the MVC Action to respond back to the $Ajax request correctly, and then have the page redrawn using the updated Viewdata. Hope this makes sense, coming down with a bad cold.

    Read the article

  • Insert value into selectlist

    - by William
    I need to insert a value into a selectlist. It isn't the "0" value (i.e. the first one that shows) but the next one which would be "Other". This is then used to display an "Other" textbox. My question is similiar to link text. EDIT: I don't know if this will help but here is the code: SelectList Titles; ViewData["TitleIsOther"] = TitleIsOther(Case); if ((bool)ViewData["TitleIsOther"]) { Titles = new SelectList((LookupCollection)this.LookupRepository.FetchByCategory(true, 0, 0, false, (int)Enums.LookupCategory.CaseTitles, _LoggedInUser.AccountId), "Id", "Name", "-1"); } else { Titles = new SelectList((LookupCollection)this.LookupRepository.FetchByCategory(true, 0, 0, false, (int)Enums.LookupCategory.CaseTitles, _LoggedInUser.AccountId), "Id", "Name"); } ViewData["Titles"] = Titles; The selected value of "-1" would be the "Other" option.

    Read the article

  • Trying to pass Model down to partial, how do I do this?

    - by mrblah
    My action creates a strongly typed viewdata, which is passed to my view. In the view, I pass the Model to the render partial method. public ActionResult Index() { ViewDataForIndex vd = new ViewDataForIndex(); vd.Users = Users.GetAll(); return View(vd); } public class ViewDataForIndex: ViewData { public IList<User> Users {get;set;} } now in the view: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ViewDataForIndex>" %> <% Html.RenderPartial("~/controls/blah.ascx", ViewData.Model); %> and in blah.ascx: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> how do I access my model now? if I wanted to create a strongly typed class for my ViewUserControl, how would I do that? inherit from?

    Read the article

  • Best practice for conditional output in ASP.NET MVC?

    - by RyanW
    I'm ramping up on ASP.NET MVC and looking at how I output messages in the view. What's the best way to do something like this? Helpers? Controls? Or just as is? <% if (ViewData.ContainsKey("message") && !string.IsNullOrEmpty(ViewData["message"].ToString())) { %> <div class="notice"> <%= ViewData["message"] %> </div> <% } %>

    Read the article

  • ASP.NET MVC Session usage

    - by Ben
    Currently I am using ViewData or TempData for object persistance in my ASP.NET MVC application. However in a few cases where I am storing objects into ViewData through my base controller class, I am hitting the database on every request (when ViewData["whatever"] == null). It would be good to persist these into something with a longer lifespan, namely session. Similarly in an order processing pipeline, I don't want things like Order to be saved to the database on creation. I would rather populate the object in memory and then when the order gets to a certain state, save it. So it would seem that session is the best place for this? Or would you recommend that in the case of order, to retrieve the order from the database on each request, rather than using session? Thoughts, suggestions appreciated. Thanks Ben

    Read the article

  • Why Date Format in ASP NET MVC Differs when used inside Html Helper?

    - by Marcio Gabe
    Hi, I just came across a very interesting issue. If I use ViewData to pass a DateTime value to the view and then display it inside a textbox, even though I'm using String.Format in the exact same manner, I get different formatting results when using the Html.TextBox helper. <%= Html.TextBox("datefilter", String.Format("{0:d}", ViewData["datefilter"]))%> <input id="test" name="test" type="text" value="<%: String.Format("{0:d}", ViewData["datefilter"]) %>" /> The above code renders the following html: <input id="datefilter" name="datefilter" type="text" value="2010-06-18" /> <input id="test" name="test" type="text" value="18/06/2010" /> Notice how the fist line that uses the Html helper produces the date format in one way while the second one produces a very different output. Any ideas why? Note: I'm currently in Brazil, so the standard short date format here is dd/MM/yyyy.

    Read the article

  • Problem with ASP.NET MVC DropDownList not displaying selected value

    - by Jova
    I have an aspx page which allows me to edit articles. Among things I can edit is which category the article belongs to. The category is chosen through a DropDownList as shown here, <%= Html.DropDownList("categoryID", (IEnumerable<SelectListItem>)ViewData["CategoryID"], new { @class = "textbox" }) %> However, the articles category isn't selected when I go to that page. The ViewData I use for the DropDownList looks like this, ViewData["CategoryID"] = new SelectList(categories, "CategoryID", "Title", article.CategoryID); Which should select the article.CategoryID as it's selected value. Have I done this wrong?

    Read the article

  • ASP.NET MVC: How to Display custom object properties in View page

    - by Shyju
    I am trying to add ASP.NET MVC features(Especially Routing) to my already existing ASP.NET Web application.I added a Controlled and View (an asp.net page) .Now i want to know how can i display the details of object of my custom class( Ex : User) in the view ? Can assign the object in ViewData collection and render it in the view ? Hows that ? I already have a Datalayer (in ADO.NET) which is running for the the current ASP.NET web app.So i want to use that. I tried this in my controller public ActionResult Index() { BusinessObject.User objUser = new BusinessObject.User(); objUser.EmailId = "[email protected]"; objUser.ProfileTitle = "Web developer with 6 yrs expereince"; ViewData["objUser"] = objUser; ViewData["Message"] = "This is ASP.NET MVC!"; return View(); } How can i use this in the view page to display the user details ? Thanks in advance

    Read the article

  • Accessing Session and IPrinciple data in a Master View in Asp.Net MCV

    - by bplus
    I currently have a abstract controller class that I all my controllers inherit from. In my master page I want to be able to access some data that will be in Session and also the currently user (IPrinciple). I read that I could use the contructor of by abstract base controller class, that is I could do something like public BaseController() { ViewData["SomeData"] = Session["SomeData"]; ViewData["UserName"] = this.User.Identity.Name; } I could then access ViewData["UserName"] etc from my master page. My problem is that both Session and User are null at this point. Does anybody know of a different approach? Thanks in advance.

    Read the article

  • MVC2 html dropdownlist is invisible

    - by Deb
    I am just trying to populate a html.dropdown list using mvc2 in VS2008. But the control is not displayed at all. Here is my code public ActionResult Index() { ViewData["Time"] = DateTime.Now.ToString(); var mdl = new List<SelectListItem>(); mdl.Add(new SelectListItem { Value = "1", Text = "Module One" }); mdl.Add(new SelectListItem { Value = "2", Text = "Module Two" }); ViewData["moduleList"] = new SelectList(mdl,"Value", "Text"); return View("MainMenu"); } and here is the markup <div> <%Html.DropDownList("moduleList", (IEnumerable<SelectListItem>)ViewData["moduleList"]); %> </div> Where did i go wrong ?

    Read the article

  • How to save checkbox checked values in Database

    - by user1298215
    How to save checkbox values in database. Below is my view code. @foreach (var item in Model) { @Html.CheckBox("statecheck", (IEnumerable<SelectListItem>)ViewData["StatesList"]) @Html.DisplayFor(modelItem => item.state_name) </br> } <input class="ASPbutton" type="submit" value="submit"/> Below is My controller. public ActionResult States() { ViewData["StatesList"] = new SelectList(am.FindUpcomingStates().ToList(), "state_id", "state_Name"); return View(); } My model is public IQueryable<state> FindUpcomingStates() { return from state in Adm.states orderby state.state_name select state; } After clicking submit button checked item state_id will be saved into database. I wrote like below in Controller, but i got true or false values, i want state_id [AcceptVerbs(HttpVerbs.Post)] public ActionResult States(string _stateName, char[] statecheck, FormCollection formvalues) { statecheck = Request.Form["statecheck"].ToArray(); ViewData["StatesList"] = new SelectList(am.FindUpcomingStates222().ToList(), "state_id", "state_id", _stateName); }

    Read the article

  • how to display selected value in drop down list in asp.net mvc?

    - by Renu123
    i want to display selected value in drop down list . the value comes from the data base. for ex suppose we want to update user profile then value for gender which is previously provided by the user should get displayed as selected value. the code that i used to display is <% string val = Convert.ToString(Model.gender); ViewData["gen"] = val; %> <%= Html.DropDownList("genderList", ViewData["gen"] as SelectList) %> but its not showing the value from the database.but viewdata get value from database but it is not showing on drop down list. thanks in advance.

    Read the article

  • MVC 2 Editor Template for Radio Buttons

    - by Steve Michelotti
    A while back I blogged about how to create an HTML Helper to produce a radio button list.  In that post, my HTML helper was “wrapping” the FluentHtml library from MvcContrib to produce the following html output (given an IEnumerable list containing the items “Foo” and “Bar”): 1: <div> 2: <input id="Name_Foo" name="Name" type="radio" value="Foo" /><label for="Name_Foo" id="Name_Foo_Label">Foo</label> 3: <input id="Name_Bar" name="Name" type="radio" value="Bar" /><label for="Name_Bar" id="Name_Bar_Label">Bar</label> 4: </div> With the release of MVC 2, we now have editor templates we can use that rely on metadata to allow us to customize our views appropriately.  For example, for the radio buttons above, we want the “id” attribute to be differentiated and unique and we want the “name” attribute to be the same across radio buttons so the buttons will be grouped together and so model binding will work appropriately. We also want the “for” attribute in the <label> element being set to correctly point to the id of the corresponding radio button.  The default behavior of the RadioButtonFor() method that comes OOTB with MVC produces the same value for the “id” and “name” attributes so this isn’t exactly what I want out the the box if I’m trying to produce the HTML mark up above. If we use an EditorTemplate, the first gotcha that we run into is that, by default, the templates just work on your view model’s property. But in this case, we *also* was the list of items to populate all the radio buttons. It turns out that the EditorFor() methods do give you a way to pass in additional data. There is an overload of the EditorFor() method where the last parameter allows you to pass an anonymous object for “extra” data that you can use in your view – it gets put on the view data dictionary: 1: <%: Html.EditorFor(m => m.Name, "RadioButtonList", new { selectList = new SelectList(new[] { "Foo", "Bar" }) })%> Now we can create a file called RadioButtonList.ascx that looks like this: 1: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> 2: <% 3: var list = this.ViewData["selectList"] as SelectList; 4: %> 5: <div> 6: <% foreach (var item in list) { 7: var radioId = ViewData.TemplateInfo.GetFullHtmlFieldId(item.Value); 8: var checkedAttr = item.Selected ? "checked=\"checked\"" : string.Empty; 9: %> 10: <input type="radio" id="<%: radioId %>" name="<%: ViewData.TemplateInfo.HtmlFieldPrefix %>" value="<%: item.Value %>" <%: checkedAttr %>/> 11: <label for="<%: radioId %>"><%: item.Text %></label> 12: <% } %> 13: </div> There are several things to note about the code above. First, you can see in line #3, it’s getting the SelectList out of the view data dictionary. Then on line #7 it uses the GetFullHtmlFieldId() method from the TemplateInfo class to ensure we get unique IDs. We pass the Value to this method so that it will produce IDs like “Name_Foo” and “Name_Bar” rather than just “Name” which is our property name. However, for the “name” attribute (on line #10) we can just use the normal HtmlFieldPrefix property so that we ensure all radio buttons have the same name which corresponds to the view model’s property name. We also get to leverage the fact the a SelectListItem has a Boolean Selected property so we can set the checkedAttr variable on line #8 and use it on line #10. Finally, it’s trivial to set the correct “for” attribute for the <label> on line #11 since we already produced that value. Because the TemplateInfo class provides all the metadata for our view, we’re able to produce this view that is widely re-usable across our application. In fact, we can create a couple HTML helpers to better encapsulate this call and make it more user friendly: 1: public static MvcHtmlString RadioButtonList<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, params string[] items) 2: { 3: return htmlHelper.RadioButtonList(expression, new SelectList(items)); 4: } 5:   6: public static MvcHtmlString RadioButtonList<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> items) 7: { 8: var func = expression.Compile(); 9: var result = func(htmlHelper.ViewData.Model); 10: var list = new SelectList(items, "Value", "Text", result); 11: return htmlHelper.EditorFor(expression, "RadioButtonList", new { selectList = list }); 12: } This allows us to simply the call like this: 1: <%: Html.RadioButtonList(m => m.Name, "Foo", "Bar" ) %> In that example, the values for the radio button are hard-coded and being passed in directly. But if you had a view model that contained a property for the collection of items you could call the second overload like this: 1: <%: Html.RadioButtonList(m => m.Name, Model.FooBarList ) %> The Editor templates introduced in MVC 2 definitely allow for much more flexible views/editors than previously available. By knowing about the features you have available to you with the TemplateInfo class, you can take these concepts and customize your editors with extreme flexibility and re-usability.

    Read the article

  • ASP MVC 2: Error with dropdownlist on POST

    - by wh0emPah
    Okay i'm new to asp mvc2 and i'm experiencing some problems with the htmlhelper called Html.dropdownlistfor(); I want to present the user a list of days in the week. And i want the selected item to be bound to my model. I have created this little class to generate a list of days + a short notation which i will use to store it in the database. public static class days { public static List<Day> getDayList() { List<Day> daylist = new List<Day>(); daylist.Add(new Day("Monday", "MO")); daylist.Add(new Day("Tuesday", "TU")); // I left the other days out return daylist; } public class Dag{ public string DayName{ get; set; } public string DayShortName { get; set; } public Dag(string name, string shortname) { this.DayName= name; this.DayShortName = shortname; } } } I really have now idea if this is the correct way to do it Then i putted this in my controller: SelectList _list = new SelectList(Days.getDayList(), "DayShortName", "DayName"); ViewData["days"] = _list; return View(""); I have this line in my model public string ChosenDay { get; set; } And this in my view to display the list: <div class="editor-field"> <%: Html.DropDownListFor(model => model.ChosenDay, ViewData["days"] as SelectList, "--choose Day--")%> </div> Now this all works perfect. On the first visit, But then when i'm doing a [HttpPost] Which looks like the following: [HttpPost] public ActionResult Registreer(EventRegistreerViewModel model) { // I removed some unrelated code here // The code below executes when modelstate.isvalid == false SelectList _list = new SelectList(Days.getDayList(), "DayShortName", "DayName"); ViewData["days"] = _list; return View(model); } Then i will have the following exception thrown: The ViewData item that has the key 'ChosenDay' is of type 'System.String' but must be of type 'IEnumerable<SelectListItem>'. This errors gets thrown at the line in my view where i display the dropdown list. I really have no idea how to solve this and tried several solutions i found online. but none of them really worked. Ty in advance!

    Read the article

  • selected value for dropdownbox in asp.net mvc using selectlist

    - by FosterZ
    hi, i have following selectlist for dropdownbox in aspnet mvc. This is the editEmployee Action controller, so while edit page is displayed i want to display a selectvalue in dropdownbox,since "SelectList" takes 3 parameters one for value,one for text and other is for selected value, here i'm not getting what should i pass in 3rd parameter, coz its asking an object for selected value. ViewData["DepartmentList"] = new SelectList(DepartmentRepository.GetDepartmentsBySchoolIdInList(ViewData["schoolId"].ToString()),"DepartmentId","DepartmentTitle"); here is the view =Html.DropDownList("DepartmentList")

    Read the article

  • mvc fill dropdownlist

    - by user276640
    i use this code to fill dropdownlist ViewData["projectType"] = new SelectList(_dataManager.Project.ProjectTypeList(), "Id", "Name"); but what i must do if i want to use not one table column but two or more columns? for example ViewData["projectType"] = new SelectList(_dataManager.Project.ProjectTypeList(), "Id", "Name1"+"Name2");

    Read the article

  • DropDownList View Model

    - by Jemes
    I'm trying to produce a dropdownlist for GetAllRoles using the role provider. I can produce the drop down in a controller using ViewData but I would like to use a View Model to produce the dropdown, but I'm unsure of the best way to create the list using a View Model? public ActionResult GetAllRoles() { ViewData["Roles"] = new SelectList(Roles.GetAllRoles()); return View(); }

    Read the article

  • How to update textbox value

    - by Thomas
    I have a textbox in my View. I input a number into the textbox, and then i want the controller to multiply the number and put the result into the textbox. How can I do that? This is what i have done already. Let's start with the View: <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Index</title> </head> <body> <div> <h2>Please enter a number</h2> <% using (Html.BeginForm()) { %> <%=Html.TextBox("number")%> <input type="submit" value="Index" name ="Index" /> <% } %> </div> </body> </html> As you can see I have a simple textbox and button. This is my controller: using System.Web.Mvc; namespace MvcApplication1.Controllers { public class HomeController : Controller { // // GET: /Home/ public ActionResult Index() { return View(); } [HttpPost] public ActionResult Index(int number) { number = number * 2; ViewData["id"] = number; return View(ViewData); } } } But nothing really happens. Yeah, I see the Post is being done, and the coded steps into public ActionResult Index(int number). I see that the number is taken from the textbox, it's multiplied correctly. I've tried using ViewData as you can see. I've also used TempData. This is another code for the textbox in the View I've tried: <%=Html.TextBox("number", ViewData["number"])%> But it doesn't matter. The textbox doesn't get updated with the new value. How can I do that?

    Read the article

  • Spark show logged in user

    - by Jose
    How do I show the username of the person logged in within a Spark View? The default MVC view engine had a Page object that you could get the info from. How would I do that in spark? I know that I could put the info into the viewdata dictionary, which is probably the best, but I don't want to have to write ViewData["User"] = myUser; before I return from EVERY action method. I'd like some feedback

    Read the article

  • Get selected value of dropdownlist in asp.net MVC

    - by Xulfee
    how can i get select value of dropdownlist and here is my code which is working fine. var list = new[] { new Person { Id = 1, Name = "Name1" }, new Person { Id = 2, Name = "Name2" }, new Person { Id = 3, Name = "Name3" } }; var selectList = new SelectList(list, "Id", "Name", 2); ViewData["People"] = selectList; <%= Html.DropDownListFor(model => model.Peoples, ViewData["People"] as IEnumerable<SelectListItem>)%>

    Read the article

  • Is there simple way how to join two RouteValueDictionary values to pass parameters to Html.ActionLin

    - by atagaew
    Hi. Look on my code that i created in a partial View: <% foreach (Customer customerInfo in Model.DataRows) {%> <tr> <td> <%=Html.ActionLink( customerInfo.FullName , ((string)ViewData["ActionNameForSelectedCustomer"]) , JoinParameters(customerInfo.id, (RouteValueDictionary) ViewData["AdditionalSelectionParameters"]) , null)%> </td> <td> <%=customerInfo.LegalGuardianName %> </td> <td> <%=customerInfo.HomePhone %> </td> <td> <%=customerInfo.CellPhone %> </td> </tr> <%}%> Here I'm building simple table that showing customer's details. As you may see, in each row, I'm trying to build a link that will redirect to another action. That action requires customerId and some additional parameters. Additional parameters are different for each page where this partial View is using. So, i decided to make Action methods to pass that additional parameters in the ViewData as RouteValueDictionary instance. Now, on the view i have a problem, i need to pass customerId and that RouteValueDictionary together into Html.ActionLink method. That makes me to figure out some way of how to combine all that params into one object (either object or new RouteValueDictionary instance) Because of the way the MVC does, i can't create create a method in the codebehind class (there is no codebihind in MVC) that will join that parameters. So, i used ugly way - inserted inline code: ...script runat="server"... private RouteValueDictionary JoinParameters(int customerId, RouteValueDictionary defaultValues) { RouteValueDictionary routeValueDictionary = new RouteValueDictionary(defaultValues); routeValueDictionary.Add("customerId", customerId); return routeValueDictionary; } ...script... This way is very ugly for me, because i hate to use inline code in the View part. My question is - is there any better way of how i can mix parameters passed from the action (in ViewData, TempData, other...) and the parameter from the view when building action links. May be i can build this link in other way ? Thanks!

    Read the article

  • mvc redirect after delay

    - by gre3ns0ul
    Hi guys, I'm recently new in MVC technology and i'm with a difficult I have a UI to create a user, and when i submit the content and all content is valid i pass a message into Viewdata["INFO"] and return a View called Info with Viewdata Informing than the usar was sucefully created. But in this moment i want to Regist a some script than, after a one delay specified the client redirects automatically to the base page "Users". Any ideas to get the best way to do it?

    Read the article

  • How do I specify attributes for a Html.TextBox helper while maintaing the value retreival from ViewD

    - by BigJoe714
    I am using the Html.TextBox helper to create textboxes. I want to set attributes on the textbox, which I understand is done using the following overload: Html.TextBox (string name, object value, object htmlAttributes) However, I want to maintain the functionality where the html helper automatically uses the value from either ViewData or ViewData.Model and I do not see a way to just specify the name and the htmlAttributes. Is this possible?

    Read the article

  • checkboxes jquery

    - by mazhar
    <% foreach (var i in (IEnumerable)ViewData["Group"]) { % " / <%= i.vcr_GroupName % <% foreach (var ik in (IEnumerable)ViewData["Feature"]) { % " / <%= ik.vcr_FeaturesName % <% } % <% } % I have created this now the thing is that when I click on any parent with parentid=0 .all its child should automatically be clicked with parentid 0 but not viceversa.How would I do it in jquery? (Like i CLICK ON SOME FEATURE Manage User its child Add user ,edit and delete user should be clicked automatically ) but if i click on add user nothing should happened

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >