logo
Tags down

shadow

How to validate that a dropdown list item has been selected


By : aming
Date : October 16 2020, 11:12 PM
hop of those help? Well, this must be easy, but ...
code :


Share : facebook icon twitter icon

Need to change selected item in dropdown list when selected item in another dropdown list changes


By : Ritoban Richard Paul
Date : March 29 2020, 07:55 AM
Any of those help Adding values to cbxUpdateAppType from the AppTable object fixed it. I'm not sure why since in either case, I was adding Strings.
I just needed to check for duplicates so I don't end up with multiple instances of the same value in my dropdown box.
code :
foreach (AppTable table in appTableList)
        {
            if (!cbxUpdateAppType.Items.Contains(table.Type))
                cbxUpdateAppType.Items.Add(table.Type);
        }

Showing values in second dropdown list corresponding to first dropdown list selected item


By : user3360737
Date : March 29 2020, 07:55 AM
I wish this help you You could create an action that accepts a ReportElem.Alusdok value and returns a JSON list of ParingElem objects.
code :
[HttpPost]
public ActionResult GetParingElems(string parentAlusdok)
{
    // construct a list formatted like this from your data layer, etc
    List<ListItem> list = new List<ListItem>() {
        new ListItem() { Value = "1", Text = "Alusdok 1" },
        new ListItem() { Value = "2", Text = "Alusdok 2" },
        new ListItem() { Value = "3", Text = "Alusdok 3" }
    };

    return Json(list);
}
$('#_Report').change(function() {
    $.ajax({
        url: 'GetParingElems',
        type: 'POST',
        data: { parentAlusdok: $('#_Report').val() },
        dataType: 'json',
        success: function(data) { // this is the returned JSON list
            $('#_Paring').remove();
            // iterate over data
            // i and optionData are arbitrary variable names
            $.each(data, function (i, optionData) {
                $('#_Paring').append(
                    $('<option></option>').val(optionData.Value).html(optionData.Text)
                );
            });
        }
    });
});

Using MVC dropdown list how to edit form and show the data in dropdown and previously selected item in dropdown?


By : user3295214
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I am using MVC4 and displaying categories in drop down list. Foam allow user to edit the previously added data. So when i perform update action all the other data that user enter can easily displayed but who to display the selected category value from drop down list and show that valve in drop down? , Your Model should contains CategoryId
code :
public int CategoryId{get;set;}
public ActionResult Edit(int id)
{
   using (var catRepo = new BusinessLayer.Repostories.CategoryRepository())
   {
      var itemToEdit=catRep.GetItemById(id);// replace your method
      ViewBag.VBCategoryList = new  SelectList(catRepo.GetAllCategories(),"CategoryId","Name",itemToEdit.CategoryId);
   }
   return View(itemEdit);
} 

How to return text input value instead of dropdown list item when certain dropdown value is selected for model binding?


By : Dkdocs
Date : March 29 2020, 07:55 AM
it should still fix some issue Use a different name for the text input like OtherGenre and add a property with that name to your view model.
code :
<input id="OtherGenre" class="form-control" type="text" name="OtherGenre" />

public class MyViewModel
{
    public string Genre {get; set;}
    public string OtherGenre {get; set;}
}
//Either overwrite Genre before saving it
public ActionResult MyPostAction(MyViewModel model)
{
    if(model.Genre == "Other") model.Genre=model.OtherGenre;

    // ...save model ...
}

//Or apply that logic when displaying it
<span>@(@Model.Genre=="Other" ? Model.OtherGenre : Model.Genre)</span>

Validate dropdown item does not occur more than once in a list of dropdown fields with the same id


By : Rana Afifi
Date : March 29 2020, 07:55 AM
I wish did fix the issue. This is simply not possible using a ValidationAttribute (either in-built or custom ones) and MVC's unobtrusive client side validation.
Validation attributes are applied to properties of a model (your class), and the context in which validation is checked is for that instance only - it has no knowledge of other instances of the model within the collection, therefore it cannot compare other instances.
code :
<select class="select" .....>
    <option value="">Please select</option>
    <option value="1">On-call</option>
    ....
<select>
<div class="error"></div> // see notes below if you using ValidationMessageFor()
var errors = $('.error');
var selects = $('.select');
$('.select').change(function() {
  var selected = $.map(selects, function(s, i) {
    return $(s).val();
  })
  $.each(selects, function(i, s) {
    var error = $(this).next('.error');
    var val = $(this).val();
    var index = i;
    if ($(this).val()) {
      var others = selected.filter(function(s, i) {
        if (i != index) {
          return s;
        }
      });
      if (others.indexOf(val) > -1) {
        error.text('Please make a unique selection');
      } else {
        error.text('');
      }
    } else {
      error.text('');
    }

  })
})
var selected = new List<int>();
for (int i = 0 i < model.Count; i++)
{
    if (selected.Contains(model[i].YourProperty))
    {
        ModelState.AddModelError("", "Please make a unique selection");
        break;
    }
    else
    {
        selected.Add(model[i].YourProperty);
    }
}
if (!ModelState.IsValid)
{
    return View(model);
}
....
if (model.Select(x => x.YourProperty).GroupBy(x => x).Any(g => g.Count() > 1))
{
    ModelState.AddModelError("", "Please make a unique selection");
}
if (selected.Contains(model[i].YourProperty))
{
    var propertyName = string.Format("[{0}].yourPropertyName", i);
    ModelState.AddModelError(propertyName, "Please make a unique selection");
    break;
}
Related Posts Related Posts :
  • .NET Remoting client config creates local object, not remote
  • Is there a possibility to differ virtual printer from physical one?
  • Print barcode which has high scan rate
  • Query string value having "&"
  • Which is best for perfomance?
  • Can we make overloaded controller method in ASP .NET MVC
  • Nested loop in StringTemplate
  • How to get SSID and RSSI for Win7 using C#
  • Send messages to applications on the network (.Net)
  • Detect and prevent/delay windows mobile power off
  • How X509 Certificate renewal does not impact the code?
  • Silverlight: How to make my custom control act like a button
  • C# basic Dictionary Ordering Just need to clear an error
  • Common c# idioms including coalesce ?? operator
  • Why Does Thread.CurrentThread.CurrentCulture Change between Page Rendering and HttpModule.PostRequestHandlerExecute?
  • COM Exception 0x8004005
  • How do I show a message box from inside a class in a class library?
  • LINQ Distinct Query
  • Issue with number guessing game c#
  • Usage of a using statement
  • Building a forms system using DDD
  • How can I programmatically tell in C# if an unmanaged lib is x86 or x64?
  • How do I get an Excel range using row and column numbers in VSTO / C#?
  • .NET 4.0 Memory Mapped Files Performance
  • db4o Indexing problem - Not Working? Poor performance?
  • Realtime Console Output Redirection using Process
  • How do C# Linq extension methods perform equality comparison?
  • internal RSS feed not working with webClient object
  • C# / Silverlight / WPF / Fast rendering lots of circles
  • how to bind table from database to checkedListBox?
  • Is it ok to catch all exception types if you rethrow them wrapped another exception?
  • Print image in .Net winform
  • Problem with StandardOutput stream in async mode
  • Partially implement an Interface
  • How to extract html links from html file in C#?
  • Windows seems to lose track of .NET application
  • Do .NET 3/4 Permits Events to be Binary De/Serialized?
  • Static Methods in ASP.NET
  • How to set an Image fit to width of ScrollViewer
  • Can C# compiler be configured to give warning when explicit cast may cause data loss?
  • How can I strip html tags in C#
  • How do i unit test a website with no backend class?
  • Is there tool that can port or compile excel VBA code to C#?
  • NUnit conflict with Debug.Assert
  • C# Adding a long string to combobox
  • Creating Wizards for Windows Forms in C#
  • How to access the main windows handle once the child window exits in a process in C#
  • Mock AutoMapper Mapper.Map call using Moq
  • Copy C# object along with reference
  • Script for changing fonts in a Word document
  • 2 equal byte[] does not return true
  • Image capture of Windows mobile 5.0 camera using C# winform
  • Magento 1.4 productIdentifierType
  • File locks when using file.move in c#...how can I stop or fix this
  • Is there a framework that works the way like updating a virus definition database?
  • How can I make use of Visual Studio's regular expression to replace multiple lines of code?
  • Configuring Threadpool Max Threads via app.config?
  • C# thread dispatcher
  • Linkbutton inside Repeater for paging ASP.Net
  • How can I perform division in a program, digit by digit?
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org