Search Results

Search found 934 results on 38 pages for 'actionresult'.

Page 23/38 | < Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >

  • MVC Pass textbox to controller if not in a form tag

    - by user1679820
    I am working on and Microsoft MVC3 project and cannot pass a parameter which has been edited to the controller. It will only pass back the original set parameter For example: @Ajax.ActionLink("share file", InviteController.Actions.Result, InviteController.Name, new { message = Model.Message }, new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "popup", OnSuccess = "$('#popup').dialog('open')" }, new { id = "popup-button" }) <label>Personal Message <span class="optional-message">(optional)</span></label> @Html.TextAreaFor(x => x.Message) </div> This will pass the to the following controller but the 'message' parameter has the original message and not the updated message: public ActionResult Result(FormCollection coll, string message) { I'd love if someone could give me some advice. Many Thanks

    Read the article

  • asp.net mvc jQuery $.post works but $.get doesn't

    - by iboeno
    Why would POST work but not GET? I'm not using [AcceptVerbs(HttpVerbs.Post)]. I'm calling this: public ActionResult GetTest(string key) { var test = new { HelpTest = key }; return Json(test); } And it works when I do this: $.post("/Home/GetTest", { key: options.key }, function(helpTest) { alert(helpTest.HelpTest); }); But not this: $.get("/Home/GetTest", { key: options.key }, function(helpTest) { alert(helpTest.HelpTest); }); Why would this be? Using GET returns an XMLHttpRequest.status of 500. What am I confused about?

    Read the article

  • ASP.NET MVC search route

    - by sahina
    I setup a search route: routes.MapRoute( "Search", "Search/{q}", new { controller = "Search", action = "Index" } ); The search form has an input box and a button. I want the search with a GET as below. <% using(Html.BeginForm("Index", "Search", FormMethod.Get)) {%> <%:Html.TextBox("q")%> <span class="query-button"> <input type="submit" value="select" /></span> <% } %> </div> The action on the SearchController is: public ActionResult Index(string q) { // search logic here return View(new SearchResult(q)); } The URL becomes like this: http://localhost:19502/search?q=mvc+is+great But I want the search to be like: http://localhost:19502/search/mvc+is+great How do I setup the route or the Html.BeginForm

    Read the article

  • How to read a complex view model on POST?

    - by Interfector
    Hello, I have an user view model that has the following properties: public User user; public List<Language> Languages; I send the above model to the view and use html helpers to build the form, so I end up with something like: <form action="/Users/Edit/5" method="post"><input id="user_UserId" name="user.UserId" type="hidden" value="5" /> First Name Last Name Email Language - en en Now, I try to read the POST in something that initially was something like : [AcceptVerbs( HttpVerbs.Post )] public ActionResult Edit( int UserId, FormCollection form ) { and cannot get the user.UserId variable, user.FirstName variable etc. Any idea what needs to be done to be able to read this kind of POST request. I'm kind of reluctant to modifying my ViewModel as it is very simple and easy to maintain as it is. Thank you.

    Read the article

  • Timespan not accepting day in MVC3

    - by middelpat
    I have a MVC3 application in which i want to set a timespan to for example 2 days and 5 hours. when i enter 02:05:00:00 it gives me the following exception: System.OverflowException: SqlDbType.Time overflow. Value '2.05:00:00' is out of range. Must be between 00:00:00.0000000 and 23:59:59.9999999. When i enter 05:00:00 it correctly saves 5 hours into the database. according to MSDN timespan has a property for days. How do i correctly set the days? Model: public class ProductionTimeVM { [Required] public TimeSpan DefaultTime { get; set; } } In my view i just use: @Html.TextBoxFor(x => x.DefaultTime) For my controller: public ActionResult SaveProductionTime(ProductionTimeVM vm) { ProductionTime productionTime = new ProductionTime(); productionTime.Default = vm.DefaultTime; //some more code } Any idea's?

    Read the article

  • Remove Validation in ASP.NET MVC 3

    - by johndoe
    I am trying to get remote validation working in ASP.NET MVC 3 but for some reason the validation never gets fired. I am returning json from the controller and in FireFox it ask me to download the files. Not sure what is going on here. Here is my code: @using(Html.BeginForm(new {Action = "ValidateUserName"})) { <text> Enter UserName: </text> @Html.TextBoxFor(x => x.UserName) <input type="submit" value="Login" /> } Here is the RegistrationViewModel: public class RegistrationViewModel { [Required(ErrorMessage = "UserName is required!")] [Remote("ValidateUserName","Home",ErrorMessage ="UserName already taken!")] public string UserName { get; set; } } And here is the HomeController: public ActionResult ValidateUserName(RegistrationViewModel registrationViewModel) { return Json(!registrationViewModel.UserName.Equals("test"),JsonRequestBehavior.AllowGet); }

    Read the article

  • jQuery ajax Data Sent to Controller are Empty only in IE

    - by saman gholami
    This is my jQuery code : $.ajax({ url: "/Ajax/GetConcertTime", type: "POST", cache: false, data: { concertID: concertID.replace("ct", ""), date: selectedDateValue }, success: function (dataFromServer) { //some codes ... }, error: function (a, b, c) { alert(c); } }); And this is my controller code for catching parameters : [HttpPost] public ActionResult GetConcertTime(string concertId, string date) { int cid = Convert.ToInt32(concertId); try { MelliConcertEntities db = new MelliConcertEntities(); var lst = (from x in db.Showtimes where x.Concert.ID == cid && x.ShowtimeDate.Equals(date) && x.IsActive == true select x.ShowtimeTime).Distinct().ToList(); JavaScriptSerializer js = new JavaScriptSerializer(); return Content(js.Serialize(lst)); } catch (Exception ex) { return Content(ex.Message); } } After debugging i know the parameters in Controller (concertId and date) are empty when i useing IE browser.but in other browser it's work properly. What should i do for this issue?

    Read the article

  • How to pass Model from a view to a partial view?

    - by chobo2
    Hi I have a view that is not strongly typed. However I have in this view a partial view that is strongly typed. How do I do I pass the model to this strongly typed view? I tried something like public ActionResult Test() { MyData = new Data(); MyData.One = 1; return View("Test",MyData) } In my TestView <% Html.RenderPartial("PartialView",Model); %> This give me a stackoverflow exception. So I am not sure how to pass it on. Of course I don't want to make the test view strongly typed if possible as what happens if I had like 10 strongly typed partial views in that view I would need like some sort of wrapper.

    Read the article

  • Pass array of models from view to controller

    - by niaher
    Is it possible to pass array of models from view to controller? How? Suppose my model is public class Car { public string Name { get; set; } public int Price { get; set; } } And I have a <form> where user can dynamically add new cars. When he submits, I want to catch it in the action method public ActionResult CreateCars(Car[] cars) Is it possible?

    Read the article

  • Error handling in controllers with MVC

    - by twrn
    Does it make sense to do error handling and logging inside actions methods or handle the OnException method inside the controllers. One way means writing try/catches in all the action methods even when there is nothing to be done to recover from the error. Handling this at the controller level would allow logging and redirection to an error handler page without writing try/catches inside all the action methods. Which method makes the most sense? Here is example code of try/catches in an action method. [HttpPost] public ActionResult Delete(int id) { using (new Tracer("Project Controller")) { try { Logger.Write("Deleting project"); projService.DeleteProject(id); TempData["message"] = "Project Deleted successfully"; } catch (System.Exception ex) { HandleException(ex, "Project could not be deleted."); } return RedirectToAction("List"); } }

    Read the article

  • JQUERY ajax passing null value from MVC View to Controller

    - by Piyush Sardana
    hi guys i'm posting some data to controller using jquery ajax, but i am getting null values in my controller, jQuery code is: $('#registerCompOff').click(function() { var compOff = []; $('div').each(function() { var curRow = {}; curRow.Description = $(this).find('.reason').val(); curRow.CompOffDate = $(this).find('.datefieldWithWeekends').val(); if (curRow.Description != null && curRow.CompOffDate != null) { compOff.push(curRow); } }); $.ajax({ type: 'POST', url: this.href, dataType: 'json', data: compOff }); return $('form').valid(); });? compOff is not null I have checked that... controller is: [HttpPost] public ActionResult RegisterCompOff(RegisterCompOff[] registerCompOff) { //return View(); } can you tell me where i'm going wrong?

    Read the article

  • In .NET MVC, is there an easy way to check if I'm on the home page?

    - by Hairgami_Master
    I need to take a particular action if a user logs in from the home page. In my LogOnModel, I have a hidden field: @Html.Hidden("returnUrl", Request.Url.AbsoluteUri) In my Controller, I need to check if that value is the Home page or not. In the example below, I'm checking to see if the user is on a particular page ("Account/ResetPassword"). Is there a way to check to see if they're on the home page without resorting to regular expressions? [HttpPost] public ActionResult LogOnInt(LogOnModel model) { if (model.returnUrl.Contains("/Account/ResetPassword")) { return Json(new { redirectToUrl = @Url.Action("Index","Home")}); } Any ideas? A million thanks!

    Read the article

  • Set cookie value before view loaded in MVC?

    - by James123
    I need to set a cookie value before my view called. otherwise I have to refresh the page to get cookie value in the view. The problem here is the value of cookie will get in controller. [HttpGet] [Route("Abstract/{meetingCode}")] [AllowAnonymous] public ActionResult Index(string meetingCode) { var meetingAbstract = new MeetingAbstract(); meetingAbstract.Meeting = _abstractContext.GetMeetingWithMeetingCode(meetingCode); if (meetingAbstract.Meeting != null) { var cookie = new HttpCookie("_culture"); cookie.Value = meetingAbstract.Meeting.language.language_locale_code;//"en-US"; cookie.Expires = DateTime.Now.AddDays(365); cookie.Path = "/"; this.ControllerContext.HttpContext.Response.Cookies.Add(cookie); ... Any other way without refresh the page again to set cookie value?

    Read the article

  • update database problem with asp.net mvc 2

    - by ognjenb
    [AcceptVerbs(HttpVerbs.Post)] public ActionResult Numbers(int id, int val, int name) { int temp = val % 2; brojevi br = new brojevi(); if (temp == 1 && name == 1) { var nmb = (from n in numbers.brojevi where n.prvi_br == id select n).First(); br.prvi_br = nmb.prvi_br - 1; numbers.SaveChanges(); } var nm = from n in numbers.brojevi select n; return View(nm); } Data table brojevi have 3 fields but I have to change(update) only one of them (prvi_br). Why my solutions doesn't save changes to database

    Read the article

  • ASP.NET MVC 2 model properties binding order

    - by bniwredyc
    Is there a way to change order in which the default binder binds property values of model? For example I have model class A: class A { public string A1 {get; set;} public string A2 {get; set;} } and action DoSomethig: public ActionResult DoSomething(A model) { ... } I want that A2 property has been bound before the A1 property. Is it possible? Or I need to write custom binder?

    Read the article

  • ASP.NET MVC Access model data in masterpage

    - by Paul
    I have created a UserSiteBaseController that gets commonly used data and sets the data to a UserSiteBaseViewData viewmodel in a method called SetViewData public T CreateViewData<T>() where T : UserSiteBaseViewData, new() { .... } I then create specific Controllers that inherit from the UserSiteBaseController as well as viewModels that inherit from UserSiteHomeViewData and can be created in the controller like so: public ActionResult Index(string slug) { Slug = slug; var viewData = CreateUserSiteHomeViewData<UserSiteHomeViewData>(); //If invalid slug - throw 404 not found if (viewData == null) return PageNotFound(); viewData.Announcements = _announcementsData.All(slug).ToList(); return View(viewData); } private T CreateUserSiteHomeViewData<T>() where T : UserSiteHomeViewData, new() { T viewData = CreateViewData<T>(); return viewData; } The UserBaseViewData holds data that needs to be use on every page so it would be great to be able to access this data from the Masterpage in a strongly typed manner. Is this possible or am I going about this in the incorrect manner?

    Read the article

  • ASP.NET MVC2 : DateTime modelbinding via HTTP GET

    - by mathieu
    I'm getting some trouble binding a date from QueryString : I have the following model public class QueryParms { public DateTime Date { get; set; } } And the following controller action : public ActionResult Search( QueryParms query ); I have a form, with a field where I can type my date. If the form is FormMethod.Post, everything is fine, my date is correctly bound to my model. If the form is FormMethod.Get, it is not working anymore. The date is left to the default value (01/01/0001) I think it is a culture issue : When i look into the value provider, the FormValueProvider has a culture property set for my date : {fr-FR}. The QueryStringValueProvider doesn't have the culture property set. Is there a way to set this property ?

    Read the article

  • Html.ActionLink in a button

    - by Pomster
    I Am trying to connect to a method in my controller, with a button. I can connect though this link: @Html.ActionLink("Print", "Print", new { id = Model.SalesContractId}) But i Don't want a link, i want my button on my dialog to do it. I have tried the following: $('#btnDialogPrint').click(function () { location.href = '<%= Url.Action("Print", "Print", new { id = Model.SalesContractId}) %>'; }); But it just redirect me to a page that say bad request. namespace Contract.Controllers { public class ContractController : Controller { CompassEntities db = new CompassEntities(); public ActionResult Print(int id) { return View(""); // This can be removed and Print code may be added } Don't worry about the code inside i will get to that once i get inside this method. Could i maybe attach a link here? <input type="button" value="Print" id="btnDialogPrint" />

    Read the article

  • How can I get a property as an Entity in Action of Asp.Net Mvc ?

    - by Felipe
    Hi all, i'd like to know how can I get a property like an entity, for example: My Model: public class Product { public int Id { get; set; } public string Name { get; set; } public Category Category { get; set; } } View: Name: <%=Html.TextBoxFor(x => x.Name) %> Category: <%= Html.DropDownList("Category", IEnumerable<SelectListItem>)ViewData["Categories"]) %> Controller: public ActionResult Save(Product product) { /// produtct.Category ??? } and how is the category property ? It's fill by the view ? ASP.Net MVC know how to fill this object by ID ? Thanks!

    Read the article

  • ASP.NET MVC CHECKBOXES PROBLEM

    - by mazhar
    CONTROLLER public ActionResult Index() { GroupRepository grouprepository = new GroupRepository(); ViewData["Group"] = grouprepository.FindGroups(); return View(); } <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" % <% foreach (Group i in ViewData["Group"] as List) { % " checked="checked" / <% } % The thing is that it is not able to find group id and displaying the following error. What is the solution? CS1061: 'System.Text.RegularExpressions.Group' does not contain a definition for 'int_GroupId' and no extension method 'int_GroupId' accepting a first argument of type 'System.Text.RegularExpressions.Group' could be found (are you missing a using directive or an assembly reference?)

    Read the article

  • waht is the differnce between these two types using jquery

    - by kumar
    hi, $('tr td:first-child').click(function() { var foobar = $(this).text(); $("#showgrid").load('/Product/List/Item?id=' + foobar); }); when I am seding foobar value like this in the Actionresult method I am getting string id value perfectly but I am not able to display the grid? but intresting thing is when I am seding like this $("#showgrid").load('/Product/List/Item?id=' + "12345"); then I am able to display the grid.. foobar result is same 12345.. what is the differnt between these two types? can any body help me out.. thanks

    Read the article

  • What is the differnce between these two types using jquery

    - by kumar
    hi, $('tr td:first-child').click(function() { var foobar = $(this).text(); $("#showgrid").load('/Product/List/Item?id=' + foobar); }); when I am seding foobar value like this in the Actionresult method I am getting string id value perfectly but I am not able to display the grid? but intresting thing is when I am seding like this $("#showgrid").load('/Product/List/Item?id=' + "12345"); then I am able to display the grid.. foobar result is same 12345.. what is the differnt between these two types? can any body help me out.. thanks

    Read the article

  • Cascading MVC controllers with CatchAll Routes

    - by Richard
    Hi, I have an MVC app which has its routes defined with the final route being a catch all route to a "PageController" for a database driven collection of pages. What I want to achieve is to be able to plugin to the app a second controller to the catch all route which the first controller passes on to if it does not find the url recieved in the database. Effectively I want to queue up controllers with catch all actions: public ActionResult PageCatchall(string url) { var page = repository.Get<Page>(string url); if (page != null) { // Handle the request return View(page) } // Otherwise pass to a new controller ???? } Anyone have any good ideas as to how to solve this? I have tried RedirectToAction but that requires that the next controller has a different route to the action. I have tried ActionInvoker but this failed to work the way I did it.

    Read the article

  • ASP.NET MVC 2 Form Not Passing Values

    - by Wayne
    Hi, I have a strange problem happening today. I am running the latest version of the MVC V2 framework and have been having no trouble at all - I came in this morning and for some reason values aren't being passed in to actions. To clarify lets say I have something like this: <% using (Html.BeginForm("Register", "Registration", FormMethod.Post)) { %> .... <input type="submit" name="register" id="register" value="Register" /> <% } %> And in my controller I have the following: [HttpPost] public ActionResult Register(RegistrationModel model, string register) { // At this point the register string is null } This has been working fine for a while now and I have not changed anything that I can think of that would cause this to happen. Does that make sense and as anyone any idea what is going on or what I have messed up? Thanks.

    Read the article

  • Controller should not have domain logic. How faithful should one adhere to this tenet?

    - by Hao
    Quoting from page 49 of Pro ASP.NET MVC book It is certainly possible to put domain logic into a controller, even though you shouldn’t, just because it seems like it will work anyway. It’s easy to avoid this if you imagine that you have multiple UI technologies (e.g., an ASP.NET MVC application plus a native iPhone application) operating on the same underlying business domain layer (and maybe one day you will!). With this in mind, it’s clear that you don’t want to put domain logic into any of the UI layers. Why he seems to contradict himself on page 172? [HttpPost] public ActionResult CheckOut(Cart cart, ShippingDetails shippingDetails) { // Empty carts can't be checked out if (cart.Lines.Count == 0) ModelState.AddModelError("Cart", "Sorry, your cart is empty!"); if (ModelState.IsValid) { orderSubmitter.SubmitOrder(cart, shippingDetails); cart.Clear(); return View("Completed"); } else // Something was invalid return View(shippingDetails); } Related to: How to avoid placing domain logic in controller?

    Read the article

< Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >