Last post Apr 21, 2020 08:02 PM by johnboyman12
Apr 21, 2020 03:08 PM|johnboyman12|LINK
I am just switching from asp forms to mvc. I used to do this
HtmlTableCell cell1 = new HtmlTableCell();
ViewComment relyOrCommentForm0 = LoadControl("~/WebUserControls/ViewComment.ascx") as ViewComment;
I replaces my old usercontrols with
@Html.Partial("_LoginPartial") and now i am trying to access elements inside @Html.Partial("_LoginPartial") and get a handle on the partial view and add it to an elements childdren or controls. Can anyone help with any of this content? thanks.
Apr 21, 2020 03:25 PM|bruce (sqlwork.com)|LINK
no can do.
WebForms is a component model, it builds a control tree, then walks the tree to render the html. MVC / razor is a template model, the templates just produce a string. it like in WebForms the the page only used Response.Write() and no controls.
so to modify the html string, you need an html parser.
var dom = new SomeHtmlParser(Html.Partial(...));
// edit the dom
var html = dom.RenderToHtml();
Html.Raw(html); // write out the new html
You could also create a custom Html Helper that had the functionality.
But a better approach is to throw away your current programming practices and switch to template approaches.
Apr 21, 2020 08:02 PM|johnboyman12|LINK
Thanks alot I rethought my design like you said.