Search Results

Search found 567 results on 23 pages for 'mvc2'.

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

  • Asp.Net MVC2 Model Binding Problem.

    - by Pino
    Why is my controller recieving an empty model in this case? Using the following, <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<X.Models.ProductModel>" %> <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> <h2>Product</h2> <% using (Html.BeginForm() {%> <%: Html.ValidationSummary(true) %> <div class="editor-label"> Product Name </div> <div class="editor-field"> <%: Html.TextBoxFor(model => model.Name) %> <%: Html.ValidationMessageFor(model => model.Name) %> </div> <br /> <div class="editor-label"> Short Description </div> <div class="editor-field"> <%: Html.TextAreaFor(model => model.ShortDesc) %> <%: Html.ValidationMessageFor(model => model.ShortDesc) %> </div> <br /> <div class="editor-label"> Long Description </div> <div class="editor-field"> <%: Html.TextAreaFor(model => model.LongDesc) %> <%: Html.ValidationMessageFor(model => model.LongDesc) %> </div> <p> <input type="submit" value="Create" /> </p> <% } %> </asp:Content> and the following controller using System.Web.Mvc; using X.Lib.Services; using X.Models; namespace X.Admin.Controllers { public class ProductController : Controller { [HttpGet] public ActionResult ProductData() { return View(); } [HttpPost] public ActionResult ProductData(ProductModel NewProduct) { //Validate and save if(ModelState.IsValid) { //Save And do stuff. var ProductServ = new ProductService(); ProductServ.AddProduct(NewProduct); } return View(); } } }

    Read the article

  • How to add custom hooks to controllers in ASP.NET MVC2

    - by Adrian
    Hi, I've just started a new project in ASP.net 4.0 with MVC 2. What I need to be able to do is have a custom hook at the start and end of each action of the controller. e.g. public void Index() { *** call to the start custom hook to externalfile.cs (is empty so does nothing) ViewData["welcomeMessage"] = "Hello World"; *** call to the end custom hook to externalfile.cs (changes "Hello World!" to "Hi World") return View(); } The View then see welcomeMessage as "Hi World" after being changed in the custom hook. The custom hook would need to be in an external file and not change the "core" compiled code. This causes a problem as with my limited knowledge ASP.net MVC has to be compiled. Does anyone have any advice on how this can be achieved? Thanks

    Read the article

  • MVC2 Client-Side Validation for injected Ajax response

    - by radu-negrila
    Hi, I have the following scenario for an MVC 2 website. The user checks a radio. I make a jQuery GET to retrieve some html (partial view + view model). The view-model is annotated with validation attributes. I need client-side validation for the new html's inputs. I tried placing the following line in the partial view: <% Html.EnableClientValidation(); % I was naive. Also for the obtained html I use jQuery's .html to populate my placeholder, which also would execute the javascript. Not that there is any. Is is possible to update the page's validation logic and metadata after the ajax call ? Any ideas (beside remote client side validation) ? Thanks in advance.

    Read the article

  • Moving MVC2 Helpers to MVC3 razor view engine

    - by Dai Bok
    Hi, In my MVC 2 site, I have an html helper, that I use to add javascripts for my pages. In my master page I have the main javascripts I want to include, and then in the aspx pages, I include page specific javascripts. So for example, my Site.Master has something like this: .... <head> <%=html.renderScripts() %> </head> ... //core scripts for main page <%html.AddScript("/scripts/jquery.js") %> <%html.AddScript("/scripts/myLib.js") %> .... Then in the child aspx page, I may also want to include other scripts. ... //the page specific script I want to use <% html.AddScript("/scripts/register.aspx.js") %> ... So when the full page gets rendered the javascript files are all collected and rendered in the head by sitemaster placeholder function RenderScripts. This works fine. Now with MVC 3 and razor view engine, they layout pages behave differently, because now my page level javascripts are not rendered/included. Now all I see the LayoutMaster contents. How do I get the solution wo workwith MVC 3 and the razor view engine. (The helper has already been re-written to return a HTMLString ;-)) For reference: my MasterLayout looks like this: ... ... <head> @{ Html.AddJavaScript("/Scripts/jQuery.js"); Html.AddJavaScript("/Scripts/myLib.js"); } //Render scripts @html.RenderScripts() </head> .... and the child page looks like this: @{ Layout = "~/Views/Shared/MasterLayout.cshtml"; ViewBag.Title = "Child Page"; Html.AddJavaScript("/Scripts/register.aspx.js"); } .... <div>some html </div> Thanks for your help. Edit = Just to explain, if this question is not clear enough. When producing a "page" I collect all the javascript files the designers want to use, by using the html.addJavascript("filename.js") and store these in a dictionary - (1) stops people adding duplicate js files - then finally when the page is ready to render, I write out all the javascript files neatly in the header. (2) - this helper helps keep JS in one place, and prevents designers from adding javascript files all over the place. This used to work fine with Master/SiteMaster Pages in mvc 2. but how can I achieve this with razor?

    Read the article

  • ambient values in mvc2.net routing

    - by Muhammad Adeel Zahid
    Hello Everyone, i have following two routes registered in my global.asax file routes.MapRoute( "strict", "{controller}.mvc/{docid}/{action}/{id}", new { action = "Index", id = "", docid = "" }, new { docid = @"\d+"} ); routes.MapRoute( "default", "{controller}.mvc/{action}/{id}", new { action = "Index", id = "" }, new { docConstraint = new DocumentConstraint() } ); and i have a static "dashboard" link in my tabstrip and some other links that are constructed from values in db here is the code <ul id="globalnav" class = "t-reset t-tabstrip-items"> <li class="bar" id = "dashboard"> <%=Html.ActionLink("dash.board", "Index", pck.Controller, new{docid =string.Empty,id = pck.PkgID }, new { @class = "here" })%> </li> <% foreach (var md in pck.sysModules) { %> <li class="<%=liClass%>"> <%=Html.ActionLink(md.ModuleName, md.ActionName, pck.Controller, new { docid = md.DocumentID}, new { @class = cls })%> </li> <% } %> </ul> Now my launching address is localhost/oa.mvc/index/11 clearly matching the 2nd route. but when i visit any page that has mapped to first route and then come back to dash.board link it shows me localhost/oa.mvc/7/index/11 where 7 is docid and picked from previous Url. now i understand that my action method is after docid and changing it would not clear the docid. my question here is that can i remove docid in this scenario without changing the route. regards adeel

    Read the article

  • Wordpress like dynamic permalinks in ASP.NET MVC2/3 or ASP.NET 4.0

    - by Aseem Gautam
    Scenario: There are two entities say 'Books' and 'Book Reviews'. There can be multiple books and each book can have multiple reviews. Each review and book should have a separate permalink. Books and Reviews can be added by users using separate input forms. As soon as any book/review is added it should be accessible by its permalink. Anyone can point me in the right direction on how should this be implemented?

    Read the article

  • New to ASP.NET: Webforms vs MVC2

    - by Sahat
    I am new to ASP.NET Development and can't decide between developing with Webforms or MVC 2. Nevermind the pros and cons of each. I've seen mixed opinions of each. But which method would be the best for someone who has no prior experience in ASP.NET or C#? If your answer is: learn both, then which should I learn first? MVC 2 or Webforms?

    Read the article

  • DataAnnotationsModelBinder with MVC2 RTM

    - by yang
    Trying to validate models with DataAnnotations but DefaulModelBinder overrides my Required property error messages and never uses my error messages for invalid data entry. Always show 'value' is invalid for 'property name'. In another question I saw that MVC 2 uses DefaultModelBinder but I couldn't find any class in MVC 2 binaries. I downloaded the source for MVC futures and changed some source to compile it for .Net 4.0 but although I had success to compile, it has compatability problems and doesn't work as expected. Any help is aprreciated.

    Read the article

  • How to parse a url string using mvc2 routes

    - by Lavinski
    If I have a url http://www.site.com/controllerA/actionB/idC how can i extract the RouteValueDictionary where the item with the key controller would have the value of controllerA. Note this isn't for testing so I don't want to use mocking and the solution here does not seem to be working.

    Read the article

  • Writing an image to ResponseBase.OutputStream does not work anymore with ASP.NET MVC2 RC2

    - by labilbe
    The following code worked nice on ASP.NET MVC1 public class ImageResult : ActionResult { public Image Image { get; set; } public override void ExecuteResult(ControllerContext context) { if (Image == null) { return; } HttpResponseBase response = context.HttpContext.Response; response.ContentType = "image/png"; Image.Save(response.OutputStream, ImageFormat.Png); } } I spent some time searching answers but I didn't find anyone. The error thrown is OutputStream is not available when a custom TextWriter is used.

    Read the article

  • Handling MVC2 variables with hyphens in their name

    - by Jaxidian
    I'm working with some third-party software that creates querystring parameters with hyphens in their names. I was taking a look at this SO question and it seems like their solution is very close to what I need but I'm too ignorant to the underlying MVC stuff to figure out how to adapt this to do what I need. Ideally, I'd like to simply replace hyphens with underscores and that would be a good enough solution. If there's a better one, then I'm interested in hearing it. An example of a URL I want to handle is this: http://localhost/app/Person/List?First-Name=Bob with this Controller: public ActionResult List(string First_Name) { {...} } To repeat, I cannot change the querystring being generated so I need to support it with my controller somehow. But how? For reference, below is the custom RouteHandler that is being used to handle underscores in controller names and action names from the SO question I referenced above that we might be able to modify to accomplish what I want: public class HyphenatedRouteHandler : MvcRouteHandler { protected override IHttpHandler GetHttpHandler(RequestContext requestContext) { requestContext.RouteData.Values["controller"] = requestContext.RouteData.Values["controller"].ToString().Replace("-", "_"); requestContext.RouteData.Values["action"] = requestContext.RouteData.Values["action"].ToString().Replace("-", "_"); return base.GetHttpHandler(requestContext); } }

    Read the article

  • Quick MVC2 checkbox question

    - by kevinmajor1
    In order to get my EF4 EntityCollection to bind with check box values, I have to manually create the check boxes in a loop like so: <p> <%: Html.Label("Platforms") %><br /> <% for(var i = 0; i < Model.AllPlatforms.Count; ++i) { %> <%: Model.AllPlatforms[i].Platform.Name %> <input type="checkbox" name="PlatformIDs" value="<%: Model.AllPlatforms[i].Platform.PlatformID %>" /><br /> <% } %> </p> It works, but it doesn't automatically populate the group of check boxes with existing values when I'm editing a model entity. Can I fudge it with something like? <p> <%: Html.Label("Platforms") %><br /> <% for(var i = 0; i < Model.AllPlatforms.Count; ++i) { %> <%: Model.AllPlatforms[i].Platform.Name %> <input type="checkbox" name="PlatformIDs" value="<%: Model.AllPlatforms[i].Platform.PlatformID %>" checked=<%: Model.GameData.Platforms.Any(p => PlatformID == i) ? "true" : "false" %> /><br /> <% } %> </p> I figure there has to be something along those lines which will work, and am just wondering if I'm on the right track. EDIT: I'm purposely staying away from MVC's check box HTML helper methods as they're too inflexible for my needs. My check boxes use integers as their values by design.

    Read the article

  • Slow performance with MVC2 DisplayFor

    - by PretzelSteelersFan
    I'm iterating through a collection on my view model. The collection contains HealthLifeDentalRates which implement IBeginsEnds. I have a Display Template BeginsEnds that displays the date range. This results in very slow performance. If I simply the date range (see commented code), it's fine. I think how I'm defining the lambda is the problem but not sure how to change it. <% foreach (var item in Model.Data.OrderBy(x=x.HealthLifeDentalRateCode)) { % <tr> <td> <%= Html.Encode(item.FiscalPeriodString()) %> </td> <td> <%= Html.Encode(item.HealthLifeDentalRateCode) %> </td> <td> <%= Html.Encode(item.Rate) %> </td> <td> <%= Html.Encode(item.IsDental.YesNo()) %> </td> <td> <%= Html.DisplayFor(i = item, "BeginsEnds") % - <%= Html.Encode(item.Ends.ToDateString()) % -- <%= Html.Encode(String.Format("{0:g}", item.Loaded)) % - <%= Html.Encode(item.LoadedBy) % <% } %>

    Read the article

  • ASP MVC2 - Dynamic Field Layout

    - by Rob
    I'm new to MVC and ADO.net Entity Framework. Instead of having to create an edit/display for each entity, I'd like to have the controller base class generate the view and validation code based off metadata stored in a table - something along those lines. I would imagine something like this has already been done, or there are good reasons for not doing it. Any insight or suggestions are appreciated.

    Read the article

  • Accessing ArrayList in Javascript - ASP.Net MVC2

    - by Shrikant
    Hi I have ArrayList in my Model and want to iterate through it in my javascript. I am using following code but its giving me error : CS0103: The name 'i' does not exist in the current context for(var i=0; i <= <%=Model.KeyList.Count%>; i++) { alert('<%=Model.KeyList[i]%>'); } How to get rid of this. its urgent...Please.

    Read the article

  • MVC2 Json request not actually hitting the controller

    - by SlackerCoder
    I have a JSON request, but it seems that it is not hitting the controller. Here's the jQuery code: $("#ddlAdminLogsSelectLog").change(function() { globalLogSelection = $("#ddlAdminLogsSelectLog").val(); alert(globalLogSelection); $.getJSON("/Administrative/AdminLogsChangeLogSelection", { NewSelection: globalLogSelection }, function(data) { if (data.Message == "Success") { globalCurrentPage = 1; } else if (data.Message == "Error") { //Do Something } }); }); The alert is there to show me if it actually fired the change event, which it does. Heres the method in the controller: public ActionResult AdminLogsChangeLogSelection(String NewSelection) { String sMessage = String.Empty; StringBuilder sbDataReturn = new StringBuilder(); try { if (NewSelection.Equals("Application Log")) { int i = 0; } else if (NewSelection.Equals("Email Log")) { int l = 0; } } catch (Exception e) { //Do Something sMessage = "Error"; } return Json(new { Message = sMessage, DataReturn = sbDataReturn.ToString() }, JsonRequestBehavior.AllowGet); } I have a bunch of Json requests in my application, and it seems to only happen in this area. This is a separate area (I have 6 "areas" in the app, 5 of which work fine with JSON requests). This controller is named "AdministrativeController", if that matters. Does anything jump out anyone as being incorrect or why the request would not pass to the server side?

    Read the article

  • .net mvc2 custom HtmlHelper extension unit testing

    - by alex
    My goal is to be able to unit test some custom HtmlHelper extensions - which use RenderPartial internally. http://ox.no/posts/mocking-htmlhelper-in-asp-net-mvc-2-and-3-using-moq I've tried using the method above to mock the HtmlHelper. However, I'm running into Null value exceptions. "Parameter name: view" Anyone have any idea?? Thanks. Below are the ideas of the code: [TestMethod] public void TestMethod1() { var helper = CreateHtmlHelper(new ViewDataDictionary()); helper.RenderPartial("Test"); // supposingly this line is within a method to be tested Assert.AreEqual("test", helper.ViewContext.Writer.ToString()); } public static HtmlHelper CreateHtmlHelper(ViewDataDictionary vd) { Mock<ViewContext> mockViewContext = new Mock<ViewContext>( new ControllerContext( new Mock<HttpContextBase>().Object, new RouteData(), new Mock<ControllerBase>().Object), new Mock<IView>().Object, vd, new TempDataDictionary(), new StringWriter()); var mockViewDataContainer = new Mock<IViewDataContainer>(); mockViewDataContainer.Setup(v => v.ViewData) .Returns(vd); return new HtmlHelper(mockViewContext.Object, mockViewDataContainer.Object); }

    Read the article

  • asp.net mvc2 - update list of objects

    - by ile
    I want to display list of objects from database, and on the same page have option to edit them. When submitting, I'd like to submit changes to all of them. I found this link: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx and http://www.hanselman.com/blog/ASPNETWireFormatForModelBindingToArraysListsCollectionsDictionaries.aspx but there is no description how to handle posted data in controller. Thanks in advance!

    Read the article

  • How to initiate JavaScript Callback with MVC2 using RenderAction

    - by Zacho
    I am building a dashboard where I am iterating through a list of controls to render, and I need to initiate a general callback both after each control and after they are all completed. I was curious what the best way to handle this is. I can get the control specific callback fired off by placing myUserControlCallback(); in the user control itself. I'm just not sure how to run something like allControlsRendered();. Any ideas?

    Read the article

  • Return http 204 "no content" to client in ASP.NET MVC2

    - by Jeremy Raymond
    In an ASP.net MVC 2 app that I have I want to return a 204 No Content response to a post operation. Current my controller method has a void return type, but this sends back a response to the client as 200 OK with a Content-Length header set to 0. How can I make the response into a 204? [HttpPost] public void DoSomething(string param) { // do some operation with param // now I wish to return a 204 no content response to the user // instead of the 200 OK response }

    Read the article

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