MVC3 Valums Ajax File Upload

I figured it out. this works in IE and Mozilla. [HttpPost] public ActionResult FileUpload(string qqfile) { var path = @”C:\\Temp\\100\\”; var file = string.Empty; try { var stream = Request.InputStream; if (String.IsNullOrEmpty(Request[“qqfile”])) { // IE HttpPostedFileBase postedFile = Request.Files[0]; stream = postedFile.InputStream; file = Path.Combine(path, System.IO.Path.GetFileName(Request.Files[0].FileName)); } else { //Webkit, Mozilla file = Path.Combine(path, qqfile); … Read more

How can I use Html.Action?

You should look at the documentation for the Action method; it’s explained well. For your case, this should work: @Html.Action(“GetOptions”, new { pk=”00″, rk=”00″ }); The controllerName parameter will default to the controller from which Html.Action is being invoked. So if you’re trying to invoke an action from another controller, you’ll have to specify the … Read more

Unable to find the requested .Net Framework Data Provider. It may not be installed. – when following mvc3 asp.net tutorial

I was able to solve a problem similar to this in Visual Studio 2010 by using NuGet. Go to Tools > Library Package Manager > Manage NuGet Packages For Solution… In the dialog, search for “EntityFramework.SqlServerCompact”. You’ll find a package with the description “Allows SQL Server Compact 4.0 to be used with Entity Framework.” Install … Read more

ASP.net MVC – Display Template for a collection

Like this: @Html.DisplayFor(m => m.Children, “YourTemplateName”) or like this: [UIHint(“YourTemplateName”)] public IEnumerable<ChildModel> Children { get; set; } where obviously you would have ~/Views/Shared/DisplayTemplates/YourTemplateName.cshtml: @model IEnumerable<ChildModel> <table> <tr> <th>Property 1</th> <th>Property 2</th> </tr> … </table>

An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key

As mentioned by @anon you can’t attach model once you loaded the entity with the same key. The changes must be applied to attached entity. Instead of this: db.Entry(model).State = EntityState.Modified; use this: db.Entry(v).CurrentValues.SetValues(model);

Better way to get active page link in MVC 3 Razor

A better approach is to use a HTML helper: using System.Web.Mvc; using System.Web.Mvc.Html; public static class MenuExtensions { public static MvcHtmlString MenuItem( this HtmlHelper htmlHelper, string text, string action, string controller ) { var li = new TagBuilder(“li”); var routeData = htmlHelper.ViewContext.RouteData; var currentAction = routeData.GetRequiredString(“action”); var currentController = routeData.GetRequiredString(“controller”); if (string.Equals(currentAction, action, StringComparison.OrdinalIgnoreCase) && … Read more

Call MVC 3 Client Side Validation Manually for ajax posts

Try: //using the form as the jQuery selector (recommended) $(‘form’).submit(function(evt) { evt.preventDefault(); var $form = $(this); if($form.valid()) { //Ajax call here } }); //using the click event on the submit button $(‘#buttonId’).click(function(evt) { evt.preventDefault(); var $form = $(‘form’); if($form.valid()) { //Ajax call here } }); This should work with jQuery ajax and MSAjax calls. Could … Read more

Why doesn’t Visual Studio code formatting work properly for Razor markup?

Be sure to set the editor to use space characters and not tabs. The editor seems to completely lose its mind when tabs are used. This is a shame because all those space characters end up in the actual HTML output, greatly increasing the data transfer size. What I do is manually supplement the automatic … Read more

tech