Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere to form html when using asp.net mvc and jquery?
    primarykey
    data
    text
    <p>I am currently working on some prototypes for a web site I am wanting to create. Part of the web site is going to be pretty heavy with javascript. Right now I am learning the jquery and ASP.Net MVC framework combo.</p> <p>The issue I am having is where I should be forming the html generated for ajax requests. For example on page load I want to load a bulleted list called #subject_list based on what project is being loaded (i.e. navigated to /Project/Manage/3, project id is 3). From the way I see it (and I've learned both ways) I can form the <li> elements two ways:</p> <p>1) Create a JSON object on the server with the data for each object the list is representing, and on the client form the <code>&lt;li&gt;</code> string for each item in the JSON object and append it to the #subject_list's html.</p> <p>2) Create the <code>&lt;li&gt;</code> elements on the server (using partial views or strings built from data) and return the html directly to jquery, then have jquery put that html into the #subject_list.</p> <p>Now it seems like method 2 would be better performance wise, as it keeps the client from having to do the string manipulation and puts the task on the server (which is run from compiled c# code rather than interpreted javascript). </p> <p>However, I can't seem to figure out how to detect errors reliably with the 2nd method. For example, if the database connection failed, query failed, meteor destroys the planet, etc... I want the ability to return an error and display that error in a modal dialog. Unless I am looking at things wrong (which is possible), it seems that if I want to use the 2nd method, I am coding my javascript to expect html and thus don't have the option to detect if an error message occurred.</p> <p>So what is the best way to form html when using asp.net and jquery?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload