Search Results

Search found 361 results on 15 pages for 'httppost'.

Page 8/15 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • Preventing EF4 ConstraintException when invoking TryUpdateModel

    - by twk
    Given following ASP.NET MVC controller code: [HttpPost] public ActionResult Create(FormCollection collection) { string[] whitelist = new []{ "CompanyName", "Address1", "Address2", ... }; Partner newPartner = new Partner(); if (TryUpdateModel(newPartner, whitelist, collection)) { var db = new mainEntities(); db.Partners.AddObject(newPartner); db.SaveChanges(); return RedirectToAction("Details/" + newPartner.ID); } else { return View(); } } The problem is with the Entity Framework 4: the example Partner entity is mapped to a database table with it's fields NOT ALLOWED to be NULL (which is ok by design - they're required). Unfortunately, invoking TryUpdateModel when some of the properties are nulls produces ConstraintException which is not expected! I do expect that TryUpdateModel return false in this case. It is ok that EF wouldn't allow set a property value to null if it should not be, but the TryUpdateMethod should handle that, and add the error to ModelState errors collection. I am wrong, or somebody screwed the implementation of TryUpdateModel method?

    Read the article

  • Posting data using AJAX

    - by ognjenb
    public ActionResult Create() { return View(); } // // POST: /Partial/Create [HttpPost] public ActionResult Create(last_name ln) { try { // TODO: Add insert logic here proba.AddTolast_name(ln); proba.SaveChanges(); return View(); } catch { return View(); } } Part of index View: <div id="Div1"> <% using (Ajax.BeginForm("Create", new AjaxOptions { UpdateTargetId = "Div1" })) { %> <%= Html.Action("Create")%> <% } %> </div> In this solutions data from from View Create not post to database. In this solutions data posted to database <div id="Div1"> <%= Html.Action("Create")%> </div> View "Create" is strongly typed view. Why is this happening ie why the first solution does not work?

    Read the article

  • Comparing lists of objects and update

    - by user2915962
    I have a view, passing a LIST of Originals to this method. Before the post happened, i changed some of the properties. I now receive the updated list as a parameter in my method and would like to update the database with these new values. [HttpPost] public ActionResult NewValue(Page model) { var ListOfOriginals = Session.Query<Original>().ToList(); //GETS the objects i want to update listOfOriginals = Model.Pages // Model.page is the new list containing the updated values RavenSession.SaveChanges(); return RedirectToAction("Index"); } When i debug, i can see that listOfOriginals gets the new values. The problem is that i dont know how to update the RavenDB whith these new values. I tried adding this: Session.Store(listOfOriginals) before the SaveChanges() but that resulted in an error. Maybe there is a much better way of doing this?

    Read the article

  • What version of DataAnnotations is included with ASP.NET MVC 2 RTM

    - by Nick Thoresby
    I'm working on a project using Visual Studio 2008 and have moved from the the MVC 2 Preview to RTM version. We would like to use model validation such as: public class ViewModel { [Required(ErrorMessage="UserName is required.")] [StringLength(10, ErrorMessage="UserName cannot be greater than 10 chars.")] public string UserName { get; set; } } [HttpPost] public ActionResult Register(ViewModel model) { if (ModelState.IsValid){} // Always true } However the ModelState.IsValid always returns true. I have a suspicion that it might be something to do with the version of System.ComponentModel.DataAnnotations.dll that we are referencing, currently version 99.0.0.0, which seems rather odd. Does anyone know what version of this dll is included with the MVC 2 RTM for Visual Studio 2008?

    Read the article

  • Error using MVCContrib TestHelper

    - by Brian McCord
    While trying to implement the second answer to a previous question, I am receiving an error. I have implemented the methods just as the post shows, and the first three work properly. The fourth one (HomeController_Delete_Action_Handler_Should_Redirect_If_Model_Successfully_Delete) gives this error: Could not find a parameter named 'controller' in the result's Values collection. If I change the code to: actual .AssertActionRedirect() .ToAction("Index"); it works properly, but I don't like the "magic string" in there and prefer to use the lambda method that the other poster used. My controller method looks like this: [HttpPost] public ActionResult Delete(State model) { try { if( model == null ) { return View( model ); } _stateService.Delete( model ); return RedirectToAction("Index"); } catch { return View( model ); } } What am I doing wrong?

    Read the article

  • Json return code to simplify if possible.

    - by pirzada
    Can you simplify this code?. Is there anything we can do to make it more simple. I am not sure but it looks ugly to me. [HttpPost] public JsonResult UserDetailById(int userId, string username) { IQueryable<Company> repository = companyRepository.GetGridCompanies(); Employee emp = companyRepository.GetEmployee(userId); //Drop down fill var a = (from c in repository .OrderBy(c => c.companyName) select new { Id = c.companyID, Name = c.companyName }).ToArray(); var data = new { Id = emp.companyID.ToString(), Name = emp.employeeFirstname + " " + emp.employeeLastname, Fn = emp.employeeFirstname, Ln = emp.employeeLastname, Dept = emp.employeeDepartment, Sup = emp.employeeSup.ToString(), HireDate = String.Format("{0:MM/dd/yyyy}", emp.employeeHiredate), CompVm = a }; return Json(data); }

    Read the article

  • How do partialviews work in asp.net MVC when passing parameters back?

    - by Rob Ellis
    I have a page with a partialview on it which is a list of items. I have a button on it which shows the next 5 items. This is done via ajax:- using (Ajax.BeginForm("ShowUpdates", new AjaxOptions() { UpdateTargetId = "statusUpdateContainer", InsertionMode = InsertionMode.InsertAfter })) { <input type="submit" class="formbutton" value="Show More" style="width:100%;"/> } My partial view controller: [HttpPost] public ActionResult ShowUpdates(string page, string pagesize) { //get data code hidden here return PartialView("_statusUpdates"); } My question is that I need the 'page' variable to increment each time someone presses the form button which is contained within the partialview. How do I keep track of that variable?

    Read the article

  • No download dialog with FileResult

    - by majkinetor
    I am returning File result from action triggered by the form post event. I can't get download dialog. Instead, if I use: return File(Encoding.UTF8.GetBytes(reportPath), "text/plain", "Report.csv"); I get path to the file upon ajax execution in the target div. When I use return File(reportPath, "text/plain", "Report.csv"); I get content of the file in the target div. Any thoughts ? The action is declared as [HttpPost] public virtual ActionResult ExportFilter(Model model) { string outputFile = CreateReport(model); return File(....) }

    Read the article

  • save changes problem

    - by ognjenb
    // GET: /Transporter/Edit/5 public ActionResult Edit(int id) { var FilesQueryEdit = (from i in FilesEntities.transporter where i.Id == id select i).First(); return View(FilesQueryEdit); } // // POST: /Transporter/Edit/5 [HttpPost] public ActionResult Edit(int id, transporter trn) { try { // TODO: Add update logic here FilesEntities.AddTotransporter(trn); FilesEntities.SaveChanges(); return RedirectToAction("Transporters"); } catch { return View(); } } This code inserts new row after post edited data. How to modify post action result to save changes in edited row without inserting new row

    Read the article

  • ASP.NET MVC - How to Preserve ModelState Errors Across RedirectToAction?

    - by RPM1984
    Hi Guys, I have the following two action methods (simplified for question): [HttpGet] public ActionResult Create(string uniqueUri) { // get some stuff based on uniqueuri, set in ViewData. return View(); } [HttpPost] public ActionResult Create(Review review) { // validate review if (validatedOk) { return RedirectToAction("Details", new { postId = review.PostId}); } else { ModelState.AddModelError("ReviewErrors", "some error occured"); return RedirectToAction("Create", new { uniqueUri = Request.RequestContext.RouteData.Values["uniqueUri"]}); } } So, if the validation passes, i redirect to another page (confirmation). If an error occurs, i need to display the same page with the error. If i do return View(), the error is displayed, but if i do return RedirectToAction (as above), it loses the Model errors. I'm not surprised by the issue, just wondering how you guys handle this? I could of course just return the same View instead of the redirect, but i have logic in the "Create" method which populates the view data, which i'd have to duplicate. Any suggestions?

    Read the article

  • ASP.NET MVC View Not posting back to Post method and expecting a parameterless Constructor?

    - by VJ
    Hi, I am trying to post back some data using a viewmodel i have created and it works for me for one of the projects.But I am doin this right now public ActionResult Foo(string userkey) { vm.Value="Xvalue"; return View(vm); } [HttpPost] public ActionResult Foo( MyViewModel vm) { // process input if (inputOK) string value=vm.Value return RedirectToAction("Index"); return View(); } public class MyViewModel { public string Value { get; set; } public SomeClass newobj {get;set;} } public class SomeClass { public int id{get;set;} public string str{get;set;} } So it on debugging never goes into the parameter method for Post although on the view i have added a form and a button that submits and the page inherits from the viewmodel.I get an error saying it expects a parameterless constructor how do I fix this ? . I wrote an post method with no parameters and it does go into that method

    Read the article

  • Error after passing variable from jquery to code in c#

    - by Moraru Viorel
    I try to pass variable from jquery to code c# but something is wrong. I have in js this code: <script type="text/javascript"> var mySerial = '12345'; var fooUrl = '@Url.Action("Foo", "Home")'; window.location.href = fooUrl + '?mySerial' + encodeURIComponent(mySerial); </script> in controller : [HttpPost] public ActionResult Foo(string mySerial) { return View(); } After execution I keep this url: http://localhost:2214/@Url.Action("Foo",%20"Home")?mySerial12345 and I don't understand where's the problem, can someone help me?

    Read the article

  • Post serialized to xml object to mvc action

    - by Maxim
    Hello! i have 2 projects. First project send to 2-nd via http-post requests, as serialized to XML class instances. Ex: <?xml version="1.0" encoding="utf-16"?> <MyObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <UserId>test user</UserId> ... How can i recieve it in action of 2-nd project? [HttpPost] public ActionResult Index(MyObject id) { ... or like string, and deserialize after? Thanx.

    Read the article

  • Why is my form triggering the wrong controller action?

    - by COCoach
    This form has multiple submit buttons, when clicked, it calls a simple JavaScript function to change the value of a hidden input (function is called "setHidden". This worked before, after some other not relevant code, it has ceased working. Essentially, the action it is supposed to call is never called, instead it seems to default back to a previous URL. The Form: <form action="/League/RemoveOwner" method="post"> <input type="hidden" value="1007" name="lid"/> <input type="hidden" value="0" id="index" name="index"/> <input type="image" src="../../Resources/Images/Delete.png" height="12" alt="Remove Owner" title="Remove Owner" onclick="setHidden('index', '1031')"/></a> coach<br /> </form> The Controller: [HttpPost] public ActionResult RemoveOwner(int id, string index) { //yada return PartialView(); } When clicking the image, it should call the remove owner controller, instead it calls the "View" controller: public ActionResult View(int id) { //yada return View(); }

    Read the article

  • How to call a jquery function from an action method in controller?

    - by Hasan Fahim
    I have a requirement to open a popup from an action method in controller. The action method is basically registering a user. [HttpPost] public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); //------------------------------------------ //I need to call a jquery function from here //------------------------------------------ return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } return View(model); } The jquery function, present in the view, would just make a hidden DIV, visible, and set the opacity, etc, to represent a popup. I need to call such a jquery function from the controller's action method shown above.

    Read the article

  • Solr adding document cycle & wait on response issue

    - by user1585896
    I am trying to send http post request to Solr for adding 50000 documents (all individual request one after another in while loop). I am using DefaultHttpClient in java to connect to Solr and when I use execute method on my HttpPost Solr takes 3 to 4 ms to response. I have commit=false, autoCommit=false, autoSoftCommit=false. My question is why it takes that much time to response and why cycle it follows to add new document. Basically I want to send add request but do not want to commit to see how many request can Solr handle without doing any kind of commits(without having to do any disk access). My guess is with above parameter tuned off I should be hitting Solr about 10000 times every second, but my result is 300 times a second. I am generating random data to add in my code.

    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

  • 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

  • Connecting PHP Server and Android?

    - by user3439988
    I am trying to create a simple test application to transfer data back and forth between my server and Android device. The following are the things I aim for: Ability to upload data and files to the server. To be able to view my files on the server. To be able to download the files from the server to my android device. Ability of the server to send me updates on the files or notifications to my phone. I need a safe and secure way to do these things. I have tried these: HTTPPost requests onto the server and echoing the output accordingly and capturing the HTTPresponse and parsing it. For files I have tried using MultipartEntity, but I think that has been deprecated.

    Read the article

  • ASP MVC html helpers in partial views

    - by Rabbi
    I am still trying to figure out how to create reusable partial views in MVC Lets say I would like to create a partial view to display a form for submitting an address. Then in my ViewModel I have two addresses (Home address & Work Address) So I would think that in my view I call HTML.Partial for each one like this @Html.Partial("Address", Model.HomeAddress) @Html.Partial("Address", Model.WorkAddress) but what happens is instead of the fields having names like HomeAddress.Street, HomeAddress.City etc. they just have the regular field names Street, City, etc. so the binder on the HTTPPost action has no idea what to do with them Thanks in advance

    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

  • 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

  • Email is not working in Salesforce REST API for Events

    - by Hitesh
    We are using Salesforce REST OAuth API for creating events. Here is the sample - $content =json_encode(array("ActivityDateTime"=>$start,"WhoId"=>$userid,"Subject"=>$name,"StartDateTime"=>$start,"DurationInMinutes"=>30)); $obj=new sfdc_API($access_token,$instance_url); $action="sobjects/Event/"; $contactURL=$obj->apiURL($action); $obj->httpPost($contactURL,$content); // PHP Curl Post Request This code is creating an Event on Salesforce for the Contact ( Mentioned in WhoId) but its not sending the email. We want to send an email as well by Salesforce only. Thanks in advance.

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >