PDA

View Full Version : [CLOSED] PartialViewResult with FormPanel does not show in FormCollection part 2



cynsystems
Jul 28, 2014, 9:34 PM
I am using MVC/Razor to display a webpage with a partial view result based a field in the model.
I am expecting the fields in the partial view to be part of the FormCollection but they are not included in the returned collection.
I'm just wondering what I am doing wrong?

Controller

public ActionResult Edit_Partial()
{
Company c = new Company();
c.strID = "1";
c.company = "test";
c.company_inPartialView = "test_inPartialView";
c.PartialViewName = "PartialView";
return View(c);
}
public ActionResult Save_Partial(FormCollection collection)
{
Company c = new Company();
c.PartialViewName = collection["PartialViewName"];

c.strID = collection["strID"];
c.company = collection["company"];
c.company_inPartialView = collection["company_inPartialView"];
return View("Edit_Partial", c);
}

View Edit_Partial.cshtml

@model tracker.Controllers.Company
@{
ViewBag.Title = "Edit_Partial";
Layout = "~/Views/Shared/_BaseLayout_orig.cshtml";
}

<h2>Edit_Partial</h2>
@section _body
{
@(Html.X().FormPanel().ID("fp") .StandardSubmit(true).Width(1400).BodyPadding(5)
.TopBar(Html.X().Toolbar()
.Items(Html.X().Button().Text("Save").IconUrl("~/images/save.png").IconCls("x-btn-text-icon")
.DirectEvents(de =>
{
de.Click.Url = Url.Action("Save_Partial");
de.Click.EventMask.ShowMask = true;
de.Click.FormID = "fp";
})
)
)
.Items(
Html.X().Panel().ID("Panel1").ColSpan(1).Title("").Height(100).Width(400).MarginSpec("5 5 5 5")
.Items(Html.X().TextField().Name("strID").FieldLabel("strID").Value(Model.strID)
),
Html.X().Panel().ID("Panel2").ColSpan(1).Title("").Height(100).Width(400).MarginSpec("5 5 5 5")
.Items( Html.X().TextField().Name("PartialViewName").ID("PartialViewName").FieldLabel("PartialViewName").Value(Model.PartialViewName).Hidden(true),

Html.X().TextField().Name("company").ID("company").FieldLabel("company").Value(Model.company),
//Html.X().Container().ID("cPartialView").Loader(Html.X().ComponentLoader().Url(Url.Action ("PartialView")).Mode(LoadMode.Script) .Params(new { containerId = "cPartialView" })),
Html.X().Container().ID("cPartialView").ContentFromPartial(Model.PartialViewName, Model ).RenderTo("Panel2")

)
)
)
}
partial view PartialViewName.cshtml

@using Ext.Net;
@using Ext.Net.MVC;

@model tracker.Controllers.Company

@Html.X().TextField().Name("company_inPartialView").ID("company_inPartialView").FieldLabel("company_inPartialView").Width(390).Value(Model.company_inPartialView)

_BaseLayout_orig.cshtml

@{
Layout = null;
}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=100">

<html>
<head>
<title>@ViewBag.Title</title>

<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
@if (IsSectionDefined("headtag"))
{
@RenderSection("headtag", false)
}
</head>
<body>
@Html.X().ResourceManager(ViewBag.ManagerConfig as MvcResourceManagerConfig)
@RenderBody()

@if (IsSectionDefined("_body"))
{
@RenderSection("_body", false)
}
@if (IsSectionDefined("example"))
{
@RenderSection("example", true)
}
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body>
</html>


ps - I was using a component loader as in
http://http://forums.ext.net/showthread.php?38211-CLOSED-PartialViewResult-with-FormPanel-does-not-show-in-FormCollection
But the loading was very slow. This method loads at the same time as the form - but the fields on the partial view are not included in the post back form collection...

THanks!!!
Cyndi Pruett

Vladimir
Jul 29, 2014, 8:05 AM
Hi

Please use ItemsFromParrtial (instead ContentFromPartial) and remove RenderTo

cynsystems
Jul 30, 2014, 6:15 PM
That was what I was doing wrong!
Thanks!
Cyndi Pruett