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 4586068
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:35:12+00:00 2026-05-21T21:35:12+00:00

I’m having a problem getting a form to work without javascript being enabled. This

  • 0

I’m having a problem getting a form to work without javascript being enabled.

This should be enough to go on, ask if you need to know anything else – I don’t want to just put the whole solution up here!

~/Views/_ViewStart.cshtml:

@{ Layout = "~/Views/Shared/Layout.cshtml"; }

~/Views/Shared/Layout.cshtml:

@using System.Globalization; @{ CultureInfo culture = CultureInfo.GetCultureInfo(UICulture); }<!DOCTYPE html>
<html lang="@culture.Name" dir="@(culture.TextInfo.IsRightToLeft ? "rtl" : "ltr")">
<head>
  <title>AppName :: @ViewBag.Title</title>
  <link href="@Url.Content("~/favicon.ico")" rel="shortcut icon" type="image/x-icon" />
  <link href="@Url.Content("~/apple-touch-icon.png")" rel="apple-touch-icon" />  
  <link href="@Url.Content("~/Content/css/site.css")" rel="stylesheet" type="text/css" />
  <script src="@Url.Content("~/Content/js/jquery-1.6.min.js")" type="text/javascript"></script>
  <script src="@Url.Content("~/Content/js/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
  <script src="@Url.Content("~/Content/js/jquery.validate.min.js")" type="text/javascript"></script>
  <script src="@Url.Content("~/Content/js/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
  <script src="@Url.Content("~/Content/js/app.js")" type="text/javascript"></script>
  @RenderSection("SectionHead", false)
</head>
<body>
  <div id="page-container">
    <div id="nav">
      <div id="nav-user">
        @{ Html.RenderAction("LoginStatus", "Account"); }
        @{ Html.RenderPartial("CultureSelector"); }
      </div>
    </div>
    <div id="page-content">
      <h2>@ViewBag.Title</h2>
      @RenderBody()
    </div>
  </div>
</body>
</html>

~/Views/Account/Index.cshtml:

@model AccountFilterModel
@{ 
  ViewBag.Title = "Account Home";
  var loadingId = "loading" + new Random().Next();
  Model.FilterFormId = "filter-account-form";
}
@using (Ajax.BeginForm("List", "Account", Model, new AjaxOptions { UpdateTargetId = "result-list", LoadingElementId = loadingId }, new { id = "filter-account-form" })) {
  <!-- form controls and validation summary stuff -->
  <input id="filter" type="submit" value="Filter" />
  <span id="@loadingId" style="display: none">
    <img src="@Url.Content("~/Content/images/ajax-loader.gif")" alt="Loading..." />
  </span>
}
<div id="result-list">
  @{ Html.RenderAction("List", Model); }
</div>

~/Views/Account/List.cshtml:

@model FilterResultModel
@helper SortLink(AccountSort sort, SortDirection dir) {
  string display = (dir == SortDirection.Ascending ? "a" : "d"); // TODO: css here
  if (Model.Filter.SortBy != null && ((AccountSortModel)Model.Filter.SortBy).Sort == sort && dir == Model.Filter.SortOrder) {
    @:@display
  } else {
    FilterModel fm = new FilterModel(Model.Filter);
    fm.SortBy = AccountSortModel.SortOption[sort];
    fm.SortOrder = dir;
    <a href="@Url.Action("Index", "Account", fm.GetRouteValueDictionary())" onclick="@(string.Format("setFormValue('{0}', '{1}', '{2}'); setFormValue('{0}', '{3}', '{4}'); formSubmit('{0}'); return false;", Model.Filter.FilterFormId, Html.PropertyNameFor(x => x.Filter.SortOrder), dir, "AccountSort", sort))">@display</a>
  }
}

@if (Model.Results.Count > 0) {
  var first = Model.Results.First();
  <table>
    <caption>
      @string.Format(LocalText.FilterStats, Model.FirstResultIndex + 1, Model.LastResultIndex + 1, Model.CurrentPageIndex + 1, Model.LastPageIndex + 1, Model.FilteredCount, Model.TotalCount)
    </caption>
    <thead>
      <tr>
        <th>
          @Html.LabelFor(m => first.Username)
          <span class="sort-ascending">
            @SortLink(AccountSort.UsernameLower, SortDirection.Ascending)
          </span>
          <span class="sort-descending">
            @SortLink(AccountSort.UsernameLower, SortDirection.Descending)
          </span>
        </th>
        <!-- other table headers -->
      </tr>
    </thead>
    <tbody>
      @foreach (AccountModel account in Model.Results) {
        <tr>
          <td>@Html.EncodedReplace(account.Username, Model.Filter.Search, "<span class=\"filter-match\">{0}</span>")</td>
          <!-- other columns -->
        </tr>
      }
    </tbody>
  </table>
  Html.RenderPartial("ListPager", Model);
} else {
  <p>No Results</p>
}

Relevant part of AccountController.cs:

public ActionResult Index(AccountSort? accountSort, FilterModel model = null) {
  FilterModel fm = model ?? new FilterModel();
  if (accountSort.HasValue) fm.SortBy = AccountSortModel.SortOption[accountSort.Value];
  return View(fm);
}

public ActionResult List(AccountSort? accountSort, FilterModel model = null) {
  FilterModel fm = model ?? new FilterModel();
  if (accountSort.HasValue) fm.SortBy = AccountSortModel.SortOption[accountSort.Value];
  return Request.IsAjaxRequest() ? (ActionResult)PartialView("List", Service.Get(fm)) : View("Index", model);
}

With javascript enabled, this works fine – the content of div#result-list is updated as expected.

If I don’t do the Request.AjaxRequest() and just return the PartialView, then with javascript disabled I get a page with just the content of the results on it. If I have the code as above, then I get a StackOverflowException.

How do I get this to work?

Solution

Thanks to @xixonia, I discovered the problem – here is my solution:

public ActionResult List(AccountSort? accountSort, FilterModel model = null) {
  FilterModel fm = model ?? new FilterModel();
  if (accountSort.HasValue) 
    fm.SortBy = AccountSortModel.SortOption[accountSort.Value];
  if (Request.HttpMethod == "GET")
    return PartialView("List", Service.Get(fm));
  if (Request.HttpMethod == "POST")
    return Request.IsAjaxRequest() ? (ActionResult) PartialView("List", Service.Get(fm)) : RedirectToAction("Index", model);
  return new HttpStatusCodeResult((int) HttpStatusCode.MethodNotAllowed);
}
  • 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-05-21T21:35:12+00:00Added an answer on May 21, 2026 at 9:35 pm

    You can use the following extension method to determine if the request is an ajax request

    Request.IsAjaxRequest()
    

    If it is, you can return a partial view, otherwise you can return a full view or redirect.

    if(Request.IsAjaxRequest())
    {
        return PartialView("view", model);
    }
    else
    {
        return View(model);
    }
    

    edit: here’s the problem:

    The “List” is returning the “Index” view when the request is not an AJAX request:

    public ActionResult List(AccountSort? accountSort, FilterModel model = null) {
      FilterModel fm = model ?? new FilterModel();
      if (accountSort.HasValue) fm.SortBy = AccountSortModel.SortOption[accountSort.Value];
      return Request.IsAjaxRequest() ? (ActionResult)PartialView("List", Service.Get(fm)) : View("Index", model);
    }
    

    The “Index” view is rendering the “List” action:

    @{ Html.RenderAction("List", Model); }
    

    AKA: Recursion.

    You need to engineer a way to display your list without drawing the index page, or make your index page draw a partial view with your list modal as a parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into

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.