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

  • Home
  • SEARCH
  • 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 8571285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:44:54+00:00 2026-06-11T18:44:54+00:00

I am developing MVC application and using razor syntax. I want to use HTML

  • 0

I am developing MVC application and using razor syntax.

I want to use HTML code in JavaScript in cshtml file, but I get confused about how to use double quotes in JavaScript in razor syntax. Is that matter?

This is line of code:

<span class="EmpName"> @Html.ActionLink(item.Owner.FullName, "Details", "EMployee", new { id = item.OwnerId }, new { @style = "color:#1A6690;" })</span>

@Html.DisplayFor(ModelItem => item.CommentDateTime)

<span class="EmpName"><button type="button" id = "@item.Id" class="deleteComment">Delete</button></span>

And I have written below code in JavaScript, is that right?

 success: function (data) {
     $("p.p12").append
           ("<div style=\"background-color:#FAFAFA\";>Recently Added... <br /><a href=\"../../Employee/Details/" + data.OwnerID + "\">" + data.OwnerName + "</a>"
           + data.cmtDateTime + "<button type=\"button\" id = \" + data.Id  +  "\class=\"deleteComment\">Delete</button></span><br />" + data.msg + "</div>");                    
 }
  • 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-11T18:44:55+00:00Added an answer on June 11, 2026 at 6:44 pm

    and I have written below code in JScript is that right ?

    No, it doesn’t seem right. The generated HTML is broken. You need to be more careful about the syntax, things liks spaces between the attributes and the quotes are important. Also you seem to be hardcoding urls instead of using url helpers. Try like this:

    $('p.p12').append(
        '<div style="background-color:#FAFAFA;">Recently Added... <br /><a href="@Url.Action("Details", "Employee", new { id = "__id__" })'.replace('__id__', data.OwnerID) + '">' + data.OwnerName + '</a>' + data.cmtDateTime + '<span><button type="button" id=' + data.Id  + ' class="deleteComment">Delete</button></span><br />' + data.msg + '</div>'
     );
    

    or as I suggested you here which IMHO is more correct approach.

    or since you are using an AJAX call, instead of returning JSON from your controller action, return a ParialView in which you will correctly build the markup using proper HTML helpers.

    Like this:

    [HttpPost]
    public ActionResult SomeAction(SomeViewModel args)
    {
         MyViewModel model = ...
         return PartislView("_SomePartial", model);
    }
    

    and then inside your strongly typed partial (_SomePartial.cshtml) build the markup without any string concatenations and spaghetti code mixing javascript and HTML:

    @model MyViewModel
    
    <div style="background-color:#FAFAFA;">
        Recently Added... 
        <br />
        @Html.ActionLink(Model.OwnerName, "Details", "Employee", new { id = Model.OwnerID }, null)
        @HtmlDisplayFor(x => x.cmtDateTime)
        <span>
            <button type="button" id="@Model.Id" class="deleteComment">Delete</button>
        </span>
        <br />
        @HtmlDisplayFor(x => x.msg)
    </div>
    

    Now all that’s left in your AJAX success callback is to refresh the corresponding DOM section:

    success: function(html) {
        $('p.p12').append(html);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an MVC application and using Razor syntax. I am using one
I am developing MVC application and using razor syntax. In this application I am
I am developing MVC application and using razor syntax. In this application I am
I am developing MVC application and using razor syntax. In this application I am
I am developing MVC 3 application and using razor syntax. In this application I
I am developing MVC 3 application and using razor syntax. In this application I
I am developing MVC application and using razor syntax. In this application I am
I am developing MVC 3 application and using razor syntax. In this application I
I am developing an ASP.Net MVC 3 Web application using Razor Views. I have
I am developing an application using Asp.net mvc and jquery. I'd like to use

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.