Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Yasir Butt 159 posts 369 karma points
    Jul 14, 2014 @ 15:31
    Yasir Butt
    0

    ViewData is not available in MVC Partial Macro

    Hi,

    I have a simple case and i got stuck.

    I made a MacroPartial which contains a simple form and i used it in RTE. it posts on surfacecontroller and I am trying to set viewdata on error but its empty. 

    I tried to show viewdata with both ways @ViewData["error"] and because it is a macro i tried this one @ViewContext.ParentActionViewContext.ParentActionViewContext.ViewData["error"].

    No luck! can someone help me?

    Note: if i use the same form without macropartial then it works fine and i got viewdata

    Yasir

  • Ismail Mayat 4511 posts 10059 karma points MVP 2x admin c-trib
    Jul 15, 2014 @ 11:19
    Ismail Mayat
    0

    Yasir,

    Can you paste the code for your controller?

    Regards

    Ismail

  • Yasir Butt 159 posts 369 karma points
    Jul 15, 2014 @ 13:07
    Yasir Butt
    0
    public class VehicleSurfaceController : SurfaceController
    {
        //
        // GET: /Vehicle/
        [ChildActionOnly]
        public ActionResult Index(VehicleViewModel model)
        {
    
            return PartialView("VehicleForm",model);
        }
    
    
    
    
        [HttpPost]
        public ActionResult FormSubmit(TransporterVehicleModel vehicle)
        {
    
            if (!ModelState.IsValid)
            {
                ViewData.Add("error", "Det oppsett en liten feil.");
                return CurrentUmbracoPage();
            }
    
            var obj = new VehicleRepository();
            if (obj.IsVehcileExist(vehicle.Registreringsnummer))
            {
                ViewData.Add("error", "Kjøretøy med registereringnummer allerede funnet.");
                return CurrentUmbracoPage();
            }
    
            obj.AddTender(new Vehicle
                {
                    Guid = Guid.NewGuid(),
                    Date = DateTime.Now,
                    RegistrationNumber = vehicle.Registreringsnummer,
                    Name = vehicle.VehicleName,
                    KmStand = vehicle.VehicleKm,
                    ServiceLimit = vehicle.ServiceLimit,
                    Volume = vehicle.Volume,
                    UserId = Members.GetCurrentMember().Id,
                    Status = "1"
                });
    
            TempData.Add("success", "Ny kjøretøy lagret");
            return RedirectToCurrentUmbracoPage();
        }
    
    
    }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies