logo
down
shadow

DropDownListFor throwing error after posting the form


DropDownListFor throwing error after posting the form

By : user2955531
Date : November 22 2020, 10:40 AM


Share : facebook icon twitter icon
html.dropdownlistfor not posting back to controller in form

html.dropdownlistfor not posting back to controller in form


By : Vitaly Kononets
Date : March 29 2020, 07:55 AM
To fix this issue The first parameter of DropDownListFor is supposed to identify the property containing the selected value. You want this:
code :
@Html.DropDownListFor(model => model.ServiceFocus, new SelectList(Model.ServiceFocusList,"Key",
 "Value", Model.ServiceFocus), "Select a Service Focus")
@Html.DropDownListFor not posting back to controller

@Html.DropDownListFor not posting back to controller


By : João Pedro Tibério
Date : March 29 2020, 07:55 AM
Hope that helps You need to give the SelectList a different name that the property your binding to (say)
code :
ViewBag.ClassList = new SelectList(classes, "ClassId", "ClassName");` 
@Html.DropDownListFor(m => m.ClassId, ViewBag.ClassList as IEnumerable<SelectListItem>)
if(student.ClassId==0)
{
    ModelState.AddModelError("ClassId", "Select Class to Enroll in");
    return View(student);
}
[Required(ErrorMessage = "Select Class to Enroll in")] // add error message here
public int ClassId { get; set; }
@Html.DropDownListFor(m => m.ClassId, ViewBag.ClassList as IEnumerable<SelectListItem>, "--please select--")
[HttpPost]
public ActionResult Create(BusinessEntities.Student student)
{
  if (!ModelSTate.IsValid)
  {
    ViewBag.ClassList = // repopulate select list
    return View(student);
  }
  // Save and redirect
}
dropdownlistfor within a 'for' loop not posting values

dropdownlistfor within a 'for' loop not posting values


By : Diala Agomuoh
Date : March 29 2020, 07:55 AM
ASP.NET MVC - Submit Form DropDownListFor Error

ASP.NET MVC - Submit Form DropDownListFor Error


By : mohsenof
Date : March 29 2020, 07:55 AM
I wish this helpful for you As @StephenMuecke has already suggested the change, you need to populate ViewBag in POST method as well so that it will be available for your view.
code :
[HttpPost]
public ActionResult CreateCompany(Company comp)
    {
        ViewBag.CompanyType = GenericMethods.GetGenericPicks2("CompanyType2").OrderBy(e => e.Name);
        ViewBag.CompanyIndustry = GenericMethods.GetGenericPicks2("CompanyIndustry").OrderBy(e => e.Name);
        if (ModelState.IsValid)
        {
            Response.Write("Saving to DB");
            // code to save to database, redirect to other page
            return View(comp);
        }
        else
        {
            return View(comp);
        }
    }
Mysterious Rails 5 API LoadError for model when posting JSON; no error when posting as form-data

Mysterious Rails 5 API LoadError for model when posting JSON; no error when posting as form-data


By : Abulkhair Dzhamanbay
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I had the same error and I just successfully figured out the cause of this issue. It's because abstract-controller tries to wrap your parameters and transform your controller class-name to model-name. By default params-wrapper for json-requests is enabled in config/initializers/wrap_parameters.rb file. But you also can disable this functionality on controller-level by defining next line in controller:
code :
wrap_parameters format: []
Related Posts Related Posts :
  • Marshal.Copy attempted to read or write protected memory At Random Times
  • Restrict Type variable to specific class or subclass
  • Horizontal text alignment in a PdfPCell
  • C# crashing with Form.show() command, ObjectDisposedException - Deeper look / explanation please
  • Will the result of a LINQ query always be guaranteed to be in the correct order?
  • "Could not find default endpoint element that references contract"
  • Umbraco Request.QueryString is null if it's the first time the page is loaded
  • Error inconsistent accessibility method C#
  • How to program Intel Xeon Phi with C#?
  • remove nested element using regular expression
  • Is there a C# alternative to Java's vararg parameters?
  • Clear particular column values in DataTable
  • how to add event handler to programatically created checkboxes
  • Cannot apply indexing with [] to an expression of type 'System.Collections.Specialized.NameValueCollection'
  • Check for key in pre-existing dictionary in case insensitive manner
  • How to remove year from datetime object?
  • Accessing Settings in different ways
  • "This project is empty" error in Sonarqube
  • How to create reusable icon menu in Xamarin
  • Value Cannot be null in Ado.Net connectivity
  • Adding a custom/dynamic attribute when using XSD.exe
  • How to convert object to correct type
  • Automatically sign out from Forms Authentication in ASP.NET when browser is closed
  • Can a WCF service support both Buffered and Streamed transfer modes?
  • Verify a CA Certificate with a public key in C#
  • How to invoke a Web Service that requires the "patch" verb using the C# WebClient wrapper?
  • Proper way a implementing property based on generic type
  • Closing a form that is created in another thread
  • How Can You Bind a List<String> to a StackPanel
  • WPF Application Update Best Practices - Architectural Explanation
  • System.UnauthorizedAccessException in Server.MapPath()
  • Connecting and Using SQL Compact Edition in a WPF application
  • C#: weird ref in constructor to behave like "virtual field"
  • C# XDocument Load with multiple roots
  • How to decide what goes in the Domain or Application Project in a "DDD" solution?
  • How to get/set a property of an interface that is not always implemented
  • Read-only array field in unsafe struct
  • i got "Invalid attempt to call Read when reader is closed" when using sqldatareader how to solve it in a three
  • Why should I encapsulate objects in using if there is garbage collection
  • How to load Word document from byte array
  • Caliburn.Micro and ContextMenu for DataGrid Row
  • Linq "join" with a IList<T> getting "Error Unable to create a constant value.."
  • How to draw red wavy line under words in RichTextBox c# winform
  • HttpPostedFileBase returns Null MVC3
  • Refresh Dropdownlist in webform
  • How to convert serialized byte array back to its text form
  • How to do a loop to check all the variables at the same time for C#?
  • Facebook Sentiment Analysis API
  • Counting occurrences of specific letters in string
  • Module 'System.Data.Linq' Version=4.0.0.0, Culture=neutral, Publickeytoken=b77a5c561934e089' should be referenced
  • C# MVC Dynamically create view model
  • Get Executing Path of C# application when using nunit with Jenkins
  • GDI count stable near 100 but Handle count keep increasing
  • Problem adding string value to ViewBag from an MVC Action using TempData
  • Reading Excel file on condition
  • what is windows programming from C++, C# and Java perspective?
  • How to deal with C# object references in MongoDB?
  • How to create a list from filtering 2 lists with linq to object
  • Webclient calls to DownloadString cause my app to freeze
  • How to create a JSON WebService in c# ASP.Net with a valid JSON output and query with JQuery/Ajax
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org