Is it possible Render MVC control using a methodHow to render an ASP.NET MVC view as a string?Can XSLT render MVC ASP.NET Controls/Code?ASP.NET MVC: returning plaintext file to download from controller methodIntermittent asp.net mvc exception: “A public action method ABC could not be found on controller XYZ.”File Upload ASP.NET MVC 3.0In Asp.Net MVC view dont render changes in model made by controllerASP.Net MVC render view from another controller to stringHow to render a Razor View to a string in ASP.NET MVC 3?Dynamically Rendering Actions from Controller - MVCMVC 5 Razor for loop not rendering HiddenFor
Some pads on a PCB are marked in clusters and I can't understand which one is which
How would armour (and combat) change if the fighter didn't need to actually wear it?
Locked room poison mystery!
What can I do to increase the amount of LEDs I can power with a pro micro?
How to gracefully leave a company you helped start?
Is the Microsoft recommendation to use C# properties applicable to game development?
Unconventional examples of mathematical modelling
Why does this Jet Provost strikemaster have a textured leading edge?
What modifiers are added to the attack and damage rolls of this unique longbow from Waterdeep: Dragon Heist?
Bringing Power Supplies on Plane?
Is there a name for the technique in songs/poems, where the rhyming pattern primes the listener for a certain line, which never comes?
What was the intention with the Commodore 128?
A+ rating still unsecure by Google Chrome's opinion
Telephone number in spoken words
How can I communicate my issues with a potential date's pushy behavior?
How does the Moon's gravity affect Earth's oceans despite Earth's stronger gravitational pull?
Is there a fallacy about "appeal to 'big words'"?
Heyawake: An Introductory Puzzle
Did Pope Urban II issue the papal bull "terra nullius" in 1095?
Doesn't the speed of light limit imply the same electron can be annihilated twice?
Will some rockets really collapse under their own weight?
Is Thieves' Cant a language?
Airline power sockets shut down when I plug my computer in. How can I avoid that?
Solving a maximum minimum problem
Is it possible Render MVC control using a method
How to render an ASP.NET MVC view as a string?Can XSLT render MVC ASP.NET Controls/Code?ASP.NET MVC: returning plaintext file to download from controller methodIntermittent asp.net mvc exception: “A public action method ABC could not be found on controller XYZ.”File Upload ASP.NET MVC 3.0In Asp.Net MVC view dont render changes in model made by controllerASP.Net MVC render view from another controller to stringHow to render a Razor View to a string in ASP.NET MVC 3?Dynamically Rendering Actions from Controller - MVCMVC 5 Razor for loop not rendering HiddenFor
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
We are working on an MVC application. As per requirement, we need to populate a VIEW using a method. I have created a sample application. You can see the method which is using to generate control in Helper.cs
class under “Controller” folder. When we directly placing the @Html.TextBox("SampleTextBox")
code in the view it is rendering correctly. But when we generate the same code using a method, it is not rendering properly and it is showing as a plain string.
If anybody has any idea regarding this please let us know, it would be very helpful.
Sample code
Instead of adding the following code directly to view, we need to populate it using a method.
@Html.TextBox("SampleTextBox")
That is some thing like
@Html.Raw(Helper.GetStringCode())
Method:
public static string GetStringCode()
return "@Html.TextBox("SampleTextBox")";
asp.net-mvc razor
|
show 1 more comment
We are working on an MVC application. As per requirement, we need to populate a VIEW using a method. I have created a sample application. You can see the method which is using to generate control in Helper.cs
class under “Controller” folder. When we directly placing the @Html.TextBox("SampleTextBox")
code in the view it is rendering correctly. But when we generate the same code using a method, it is not rendering properly and it is showing as a plain string.
If anybody has any idea regarding this please let us know, it would be very helpful.
Sample code
Instead of adding the following code directly to view, we need to populate it using a method.
@Html.TextBox("SampleTextBox")
That is some thing like
@Html.Raw(Helper.GetStringCode())
Method:
public static string GetStringCode()
return "@Html.TextBox("SampleTextBox")";
asp.net-mvc razor
Please add relevant code to the quesiton. No one will download zip file to test your project.
– Alexander
Mar 27 at 12:12
Thanks. I have updated the question.
– Ranish
Mar 27 at 12:54
So you want to render stuff using the default HTML Helper in your own code? Then create an extension method which accepts the default HTML Helper as a parameter, and do your calls on that.
– CodeCaster
Mar 27 at 13:08
Why you want to use Razor if you can create dynamic HTML string. What is the purpose of returning razor code from the back? You should return partial view in this case and use as much razor as you want in partial view.
– Nomi Ali
Mar 27 at 13:10
are you trying to generate different types of controls based on some condition?
– Saharsh
Mar 28 at 1:48
|
show 1 more comment
We are working on an MVC application. As per requirement, we need to populate a VIEW using a method. I have created a sample application. You can see the method which is using to generate control in Helper.cs
class under “Controller” folder. When we directly placing the @Html.TextBox("SampleTextBox")
code in the view it is rendering correctly. But when we generate the same code using a method, it is not rendering properly and it is showing as a plain string.
If anybody has any idea regarding this please let us know, it would be very helpful.
Sample code
Instead of adding the following code directly to view, we need to populate it using a method.
@Html.TextBox("SampleTextBox")
That is some thing like
@Html.Raw(Helper.GetStringCode())
Method:
public static string GetStringCode()
return "@Html.TextBox("SampleTextBox")";
asp.net-mvc razor
We are working on an MVC application. As per requirement, we need to populate a VIEW using a method. I have created a sample application. You can see the method which is using to generate control in Helper.cs
class under “Controller” folder. When we directly placing the @Html.TextBox("SampleTextBox")
code in the view it is rendering correctly. But when we generate the same code using a method, it is not rendering properly and it is showing as a plain string.
If anybody has any idea regarding this please let us know, it would be very helpful.
Sample code
Instead of adding the following code directly to view, we need to populate it using a method.
@Html.TextBox("SampleTextBox")
That is some thing like
@Html.Raw(Helper.GetStringCode())
Method:
public static string GetStringCode()
return "@Html.TextBox("SampleTextBox")";
asp.net-mvc razor
asp.net-mvc razor
edited Mar 27 at 12:53
Ranish
asked Mar 27 at 11:49
RanishRanish
4232 gold badges6 silver badges24 bronze badges
4232 gold badges6 silver badges24 bronze badges
Please add relevant code to the quesiton. No one will download zip file to test your project.
– Alexander
Mar 27 at 12:12
Thanks. I have updated the question.
– Ranish
Mar 27 at 12:54
So you want to render stuff using the default HTML Helper in your own code? Then create an extension method which accepts the default HTML Helper as a parameter, and do your calls on that.
– CodeCaster
Mar 27 at 13:08
Why you want to use Razor if you can create dynamic HTML string. What is the purpose of returning razor code from the back? You should return partial view in this case and use as much razor as you want in partial view.
– Nomi Ali
Mar 27 at 13:10
are you trying to generate different types of controls based on some condition?
– Saharsh
Mar 28 at 1:48
|
show 1 more comment
Please add relevant code to the quesiton. No one will download zip file to test your project.
– Alexander
Mar 27 at 12:12
Thanks. I have updated the question.
– Ranish
Mar 27 at 12:54
So you want to render stuff using the default HTML Helper in your own code? Then create an extension method which accepts the default HTML Helper as a parameter, and do your calls on that.
– CodeCaster
Mar 27 at 13:08
Why you want to use Razor if you can create dynamic HTML string. What is the purpose of returning razor code from the back? You should return partial view in this case and use as much razor as you want in partial view.
– Nomi Ali
Mar 27 at 13:10
are you trying to generate different types of controls based on some condition?
– Saharsh
Mar 28 at 1:48
Please add relevant code to the quesiton. No one will download zip file to test your project.
– Alexander
Mar 27 at 12:12
Please add relevant code to the quesiton. No one will download zip file to test your project.
– Alexander
Mar 27 at 12:12
Thanks. I have updated the question.
– Ranish
Mar 27 at 12:54
Thanks. I have updated the question.
– Ranish
Mar 27 at 12:54
So you want to render stuff using the default HTML Helper in your own code? Then create an extension method which accepts the default HTML Helper as a parameter, and do your calls on that.
– CodeCaster
Mar 27 at 13:08
So you want to render stuff using the default HTML Helper in your own code? Then create an extension method which accepts the default HTML Helper as a parameter, and do your calls on that.
– CodeCaster
Mar 27 at 13:08
Why you want to use Razor if you can create dynamic HTML string. What is the purpose of returning razor code from the back? You should return partial view in this case and use as much razor as you want in partial view.
– Nomi Ali
Mar 27 at 13:10
Why you want to use Razor if you can create dynamic HTML string. What is the purpose of returning razor code from the back? You should return partial view in this case and use as much razor as you want in partial view.
– Nomi Ali
Mar 27 at 13:10
are you trying to generate different types of controls based on some condition?
– Saharsh
Mar 28 at 1:48
are you trying to generate different types of controls based on some condition?
– Saharsh
Mar 28 at 1:48
|
show 1 more comment
1 Answer
1
active
oldest
votes
You could add a partial view for the Kendo Grid in the Shared folder and add an Html helper extension that returns your partial view:
Partial view Shared/_KendoGrid.cshtml
:
@model CustomViewModel
@(Html.Kendo().Grid()...)
Html helper method:
public static MvcHtmlString KendoGrid(this HtmlHelper helper, string header)
return helper.Partial("Shared/_KendoGrid", new CustomViewModel Header = header );
In your .cshtml
:
@Html.KendoGrid("Custom header")
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55376483%2fis-it-possible-render-mvc-control-using-a-method%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could add a partial view for the Kendo Grid in the Shared folder and add an Html helper extension that returns your partial view:
Partial view Shared/_KendoGrid.cshtml
:
@model CustomViewModel
@(Html.Kendo().Grid()...)
Html helper method:
public static MvcHtmlString KendoGrid(this HtmlHelper helper, string header)
return helper.Partial("Shared/_KendoGrid", new CustomViewModel Header = header );
In your .cshtml
:
@Html.KendoGrid("Custom header")
add a comment |
You could add a partial view for the Kendo Grid in the Shared folder and add an Html helper extension that returns your partial view:
Partial view Shared/_KendoGrid.cshtml
:
@model CustomViewModel
@(Html.Kendo().Grid()...)
Html helper method:
public static MvcHtmlString KendoGrid(this HtmlHelper helper, string header)
return helper.Partial("Shared/_KendoGrid", new CustomViewModel Header = header );
In your .cshtml
:
@Html.KendoGrid("Custom header")
add a comment |
You could add a partial view for the Kendo Grid in the Shared folder and add an Html helper extension that returns your partial view:
Partial view Shared/_KendoGrid.cshtml
:
@model CustomViewModel
@(Html.Kendo().Grid()...)
Html helper method:
public static MvcHtmlString KendoGrid(this HtmlHelper helper, string header)
return helper.Partial("Shared/_KendoGrid", new CustomViewModel Header = header );
In your .cshtml
:
@Html.KendoGrid("Custom header")
You could add a partial view for the Kendo Grid in the Shared folder and add an Html helper extension that returns your partial view:
Partial view Shared/_KendoGrid.cshtml
:
@model CustomViewModel
@(Html.Kendo().Grid()...)
Html helper method:
public static MvcHtmlString KendoGrid(this HtmlHelper helper, string header)
return helper.Partial("Shared/_KendoGrid", new CustomViewModel Header = header );
In your .cshtml
:
@Html.KendoGrid("Custom header")
answered Mar 28 at 12:55
Martin D.Martin D.
1,0151 gold badge14 silver badges23 bronze badges
1,0151 gold badge14 silver badges23 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55376483%2fis-it-possible-render-mvc-control-using-a-method%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please add relevant code to the quesiton. No one will download zip file to test your project.
– Alexander
Mar 27 at 12:12
Thanks. I have updated the question.
– Ranish
Mar 27 at 12:54
So you want to render stuff using the default HTML Helper in your own code? Then create an extension method which accepts the default HTML Helper as a parameter, and do your calls on that.
– CodeCaster
Mar 27 at 13:08
Why you want to use Razor if you can create dynamic HTML string. What is the purpose of returning razor code from the back? You should return partial view in this case and use as much razor as you want in partial view.
– Nomi Ali
Mar 27 at 13:10
are you trying to generate different types of controls based on some condition?
– Saharsh
Mar 28 at 1:48