Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7794669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:50:32+00:00 2026-06-01T22:50:32+00:00

So I am trying to convert this razor syntax in a .cshtml view into

  • 0

So I am trying to convert this razor syntax in a .cshtml view into a helper extension in .cs. There is an awesome post on this by Darin here: https://stackoverflow.com/a/8187441/1026459. However, I am having some issues getting it to work.

This is the plain markup

@using (Html.BeginForm("Restore", "GlobalCrud"))
{
 @Html.Hidden("entityId", "Id")
 <input class="ui-icon ui-icon-power" type="submit" 
  onclick="return confirm('Clicking OK will restore this record');" 
 />
}

This is the extention

public static MvcHtmlString EditOrDelete(this HtmlHelper html)
{
  var s = html.BeginForm();
  return MvcHtmlString.Create(s + " additional fields " + "</form>");
}

This is the use:

@using namespace.CustomHelper
@Html.EditOrDelete()

This is the output:

<form method="post" action="/Completed/Manage">
System.Web.Mvc.Html.MvcForm additional fields 
</form>

The helper extention for the most part produces what I need. However, I am uncertain how I should be converting this back to a proper html string. The return includes System.Web.Mvc.Html.MvcForm in the text. I am adding " additional fields " for brevity here because there is no issue there. The addition of </form> is there because I know that the normal using statement that goes with @Html.BeginForm() adds the </form> tag when it disposes.

How can I properly return the form generated by .BeginForm?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:50:34+00:00Added an answer on June 1, 2026 at 10:50 pm
    public static class HtmlExtensions
    {
        public static void EditOrDelete(this HtmlHelper html)
        {
            using (html.BeginForm())
            {
                html.ViewContext.Writer.Write("additional fields");
            }
        }
    }
    

    and then:

    @using namespace.CustomHelper
    @{Html.EditOrDelete();}
    

    emits:

    <form action="/" method="post">additional fields</form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert a MVC aspx page into a Razor view. <%@
I'm trying to convert this adaptive bayesian rating formula into PHP code: see here
Trying to convert this c code into MIPS and run it in SPIM. int
I'm trying to convert this 2012-03-27 16:01:48 CEST into 1 hour and 22 minutes
Question: I'm trying out to convert this here: http://support.microsoft.com/kb/828736 to VB.net I got it
I'm trying to use gson to convert this returned JSON into some kind of
I'm trying to convert this VB.NET / C# declaration into a Visual Basic 6.0
I'm trying to convert this SQL into a Linq2SQL query, however, I'm at the
I'm trying to convert this c# code into c++/cli code: class MyRange : IEnumerable<int>
I'm trying to convert this into a strongly typed model instead of ViewData. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.