Trying to assigning hyperlink to pdf location inside PDF using c# asp.net web forms.

below is my c# code assigned link url to pdf location.

 protected void FillPDF()
  {

Dictionary<string, string> formFieldMap;

pdfPath = Path.Combine(Server.MapPath("../img/fullapplication_final.pdf"), ""); // need to take
formFieldMap = PDFHelper.GetFormFieldNames(pdfPath);
string livepath = "http://www.example.com/";
if (!string.IsNullOrEmpty(Request.QueryString["RegistrationId"].ToString() as string))
{
    bo.Para1 = Request.QueryString["RegistrationId"].ToString();
    bo.Para2 = "3";
    DataTable dt = bl.Admin_Get_UserInformation(bo);

   formFieldMap["text_attchedfilertpin"] = livepath + "TrainingPlan/" + dt.Rows[0]["TrainingPlan"].ToString();

      }}

above code output is showing url like: www.example.com/my.pdf

But i need output like this : click here to donwload pdf

I am trying below new code to get output as i need.

    HyperLink DynLink = new HyperLink();
    DynLink.ID = "DynLink1";
    DynLink.Text = "click here to donwload pdf";
    DynLink.NavigateUrl = livepath + "TrainingPlan/" + dt.Rows[0]["TrainingPlan"].ToString();
    Page.Controls.Add(DynLink);

     not able to assign view of pdf using formFieldMap["text_attchedfilertpin"]

i am looking for your help thank you in advance.

SCENARIO I have a class with a different number of attributes. One of them is a string.

OBJECTIVE Check if a list of string is included in that attribute.

EXAMPLE The string attribute could be a description of a car, just like:

"Chevrolet 100 has 3000cc, using 250Cv. The 55/95 tires are included in the price. Just for 2 PAX... etc ..."

And the checking list could be:

"3000cc", "250Cv", "55/95 tires"

So my code would be:

         Class_A
int      id
int      price
string   definition

Class_A car = new Class_A()
{
    id = 1,
    price = 100000,
    definition = "Chevrolet 100 has 3000cc, using 250Cv. The 55/95 tires are 
    included in the price. Just for 2 PAX... etc ..."
}

List<string> checkingList = new List<string>();
checkingList.Add("3000cc");
checkingList.Add("250Cv");
checkingList.Add("55/95 tires");

As examples I tried:

bool sucess;
sucess = car.Select(p => p.definition.Contains(checkingList)).FirstorDefault();
sucess = car.Select(p => p.Where(o => o.definition.Contains(checkingList)).FirstorDefault();
sucess = car.Select(p => p.Where(o => o.definition.ForEach.Contains(checkingList)).FirstorDefault();

Thanks in advance mates.

I have an asp.net site. I wanted to use FluentMigrator, which requires 4.6.1, so I decided to upgrade the projects from 4.5 to 4.6.1. Since then, I can't deploy to our production server. Local debugging, and deploying to our dev server (debug) work fine. It's only when deploying as release to the prod server that I get this message:

2>(5/25/2018 6:44:40 PM) An error occurred when the request was processed on the remote computer.

2>Unable to perform the operation. Please contact your server administrator to check authorization and delegation settings.

I have tried a complete nuget re-install and upgrade of all packages. I even deleted the packages folder and restored everything. Also deploying with pre-compilation. The compilation seems to work fine, just the deploying part that screws up.

Here is the complete output from the build process if it's of any interest.

Pastebin

I realize it's not much to go on, but it's as much as i've got. Thanks to anyone who has the patience to help with this...

Chart work fine butt can't see tooltips… I cant find where problem is and what I missing…

<div style="width: 1000px; height: 600">
<canvas id="myChart" ></canvas>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
<script>
    var ctx = document.getElementById("myChart").getContext('2d');
    var myNewChart = new Chart(ctx, {
        type: 'line',
        data: {
            labels: ["24.5.2018. 15:23:48", "24.5.2018. 16:00:00", "24.5.2018. 17:00:00", ],
            datasets: [{
                label: '# Temperature',
                fill: false,
                data: [29, 25, 24,  ],
                backgroundColor: [
                               ],
                borderColor: [
                               ],
                borderWidth: 1
            }, {
                label: '# Humidity',
                data: [54, 62, 64,  ],
                borderColor: [
          ],
                borderWidth: 1,
                fill: false,
                type: 'line'
            }
        ]
        },
    options: {
    legend: {
      display: true,
      position: 'top',
      labels: {
        boxWidth: 80,
        fontColor: 'rgb(60, 180, 100)'
      }
    },
    tooltips: {
      cornerRadius: 4,
      caretSize: 4,
      xPadding: 16,
      yPadding: 10,
      backgroundColor: 'rgba(0, 150, 100, 0.9)',
      titleFontStyle: 'normal',
      titleMarginBottom: 15
    }
  }
    });
</script>

Helper seed that I need add more text for posting this but dont konw how simple question make longer…. text text Helper seed that I need add more text for posting this but dont konw how simple question make longer….

Current project:

  • DotNet 4.7
  • MVC 5
  • Database-first and generated from a very old Web Forms database (nchar fields and the like… don’t ask why)

So I am experiencing extremely bizarre behaviour from Fluent Validation.

To wit,

Non-Nulled Nullable fields validate only on the server-side. Take an int (and NOT an int?) field that is supposed to be populated by a drop-down menu's value, and while it will validate on the server-side, it will only de-validate on the client side. It will not re-validate on the client side if you choose a non-acceptable null value ("Select a choice") again.

This behaviour appears to be limited to int fields that are filled from drop-down lists.

All strings, dates and any other types of fields fail to validate on the client side until the form is submitted (once greedy validation kicks in), and will not validate at all on the server side. Plus, all .NotEmpty() and .NotNull() declarations appear to be ignored, even when they are the only one in the validation for a string field.

I have my Global.asax.cs properly configured:

public class MvcApplication : System.Web.HttpApplication {
  protected void Application_Start() {
    AreaRegistration.RegisterAllAreas();
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
    FluentValidationModelValidatorProvider.Configure();
  }
}

I have the correct JS files coming into the page:

<link href="/Content/bootstrap.css" rel="stylesheet"/>
<link href="/Content/bootstrap-datepicker3.css" rel="stylesheet"/>
<link href="/Content/fontawesome-all.css" rel="stylesheet"/>
<link href="/Content/style.css" rel="stylesheet"/>
<script src="/Scripts/modernizr-2.8.3.js"></script>
<script src="/Scripts/jquery-3.3.1.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/bootstrap-datepicker.js"></script>
<script src="/Scripts/popper.js"></script>
<script src="/Scripts/jquery.mask.js"></script>
<script src="/Scripts/script.js"></script>

My ViewModel is appropriately configured:

namespace Project.Models {
  using Controllers;
  using FluentValidation.Attributes;
  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.ComponentModel.DataAnnotations;
  using System.Web.Mvc;
  using Validators;

  [Validator(typeof(MoreInfoValidator))]
  public class MoreInfoViewModel {
    [DisplayName(@"First Name")]
    public string FirstName { get; set; }
    [DisplayName(@"Last Name")]
    public string LastName { get; set; }
    [DisplayName(@"Phone Number")]
    [DataType(DataType.PhoneNumber)]
    public string Phone { get; set; }
    [DisplayName(@"eMail Address")]
    [DataType(DataType.EmailAddress)]
    public string Email { get; set; }
    [DisplayName(@"Date of Birth")]
    [DataType(DataType.DateTime)]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
    public DateTime Dob { get; set; } = DateTime.Now.AddYears(-16);
    [DisplayName(@"Mailing Address")]
    public string Address { get; set; }
    [DisplayName(@"City")]
    public string City { get; set; }
    [DisplayName(@"Province or State")]
    public string ProvState { get; set; }
    [DisplayName(@"Postal Code")]
    [DataType(DataType.PostalCode)]
    public string Postal { get; set; }
    [DisplayName(@"Country")]
    public int CountryId { get; set; }
    [DisplayName(@"How did you hear about us?")]
    public int HowHeardId { get; set; }
    [DisplayName(@"Training Site")]
    public int TrainingSiteId { get; set; }
    [DisplayName(@"Comments")]
    public string Comments { get; set; }

    public IEnumerable<SelectListItem> HowHeardList = ListController.HowHeardList();
    public IEnumerable<SelectListItem> CountryList = ListController.CountryList();
    public IEnumerable<SelectListItem> TrainingSiteList = ListController.TrainingSiteList();
  }
}

I have my validators properly configured:

namespace Project.Validators {
  using FluentValidation;
  using Models;

  public class MoreInfoValidator : AbstractValidator<MoreInfoViewModel> {
    public MoreInfoValidator() {
      RuleFor(x => x.FirstName)
        .Cascade(CascadeMode.StopOnFirstFailure)
        .NotEmpty().WithMessage("You must provide a first name of some kind.")
        .MinimumLength(2).WithMessage(@"A first name must be at least two characters or longer.");
      RuleFor(x => x.LastName)
        .Cascade(CascadeMode.StopOnFirstFailure)
        .NotEmpty().WithMessage(@"You must provide a last name of some kind.")
        .MinimumLength(2).WithMessage(@"A last name must be at least two characters or longer.");
      RuleFor(x => x.Email.Trim())
        .Cascade(CascadeMode.StopOnFirstFailure)
        .NotEmpty().WithMessage(@"Please provide an eMail address to act as the login username.")
        .EmailAddress().WithMessage(@"Please provide a valid eMail address to act as the login username.");
      RuleFor(x => x.Phone)
        .Cascade(CascadeMode.StopOnFirstFailure)
        .NotEmpty().WithMessage("Please enter a valid 10-digit phone number.")
        .Length(12, 12).WithMessage("Phone number must be in the form of &#8220;123-456-7890&#8221;")
        .Matches(@"^\d{3}-\d{3}-\d{4}$").WithMessage("Phone number must be a valid 10-digit phone number with dashes, in the form of &#8220;123-456-7890&#8221;");
      RuleFor(x => x.Address)
        .Cascade(CascadeMode.StopOnFirstFailure)
        .NotEmpty().WithMessage("Please provide your street address.")
        .MinimumLength(6).WithMessage("Addresses should be at least 6 characters long.");
      RuleFor(x => x.City)
        .Cascade(CascadeMode.StopOnFirstFailure)
        .NotEmpty().WithMessage("Please provide your city.")
        .MinimumLength(2).WithMessage("City names should be at least 2 characters long.");
      RuleFor(x => x.ProvState)
        .Cascade(CascadeMode.StopOnFirstFailure)
        .NotEmpty().WithMessage("Please provide your province or state.")
        .Length(2).WithMessage("Please provide the 2-character code for your province or state.");
      RuleFor(x => x.CountryId)
        .NotEmpty().WithMessage("Please choose your country.");
      RuleFor(x => x.HowHeardId)
        .NotEmpty().WithMessage("How did you hear of us?");
      RuleFor(x => x.TrainingSiteId)
        .NotEmpty().WithMessage("Please choose a desired training site.");
    }
  }
}

My forms are correctly built:

@model Project.Models.MoreInfoViewModel
@{
  ViewBag.Title = "More Info";
}
<h1>@ViewBag.Title</h1>
<p><span class="requiredcolor">These fields</span> are required.</p>
@using(Html.BeginForm()) {
  @Html.AntiForgeryToken()
  @Html.ValidationMessage("", new { @class = "alert" })
  <div class="row">
    <div class="form-group col-md-6">
      @Html.LabelFor(x => x.FirstName, new { @class = "control-label required" })@Html.EditorFor(x => x.FirstName, new { htmlAttributes = new { @class = "form-control required", maxlength = 100 } })
      @Html.ValidationMessageFor(x => x.FirstName)
    </div>
    <div class="form-group col-md-6">
      @Html.LabelFor(x => x.LastName, new { @class = "control-label required" })@Html.EditorFor(x => x.LastName, new { htmlAttributes = new { @class = "form-control required", maxlength = 100 } })
      @Html.ValidationMessageFor(x => x.LastName)
    </div>
  </div>
  <div class="row">
    <div class="form-group col-md-4">
      @Html.LabelFor(x => x.Phone, new { @class = "control-label required" })@Html.EditorFor(x => x.Phone, new { htmlAttributes = new { @class = "form-control required phone", maxlength = 12 } })
      @Html.ValidationMessageFor(x => x.Phone)
    </div>
    <div class="form-group col-md-4">
      @Html.LabelFor(x => x.Email, new { @class = "control-label required" })@Html.EditorFor(x => x.Email, new { htmlAttributes = new { @class = "form-control required", maxlength = 75 } })
      @Html.ValidationMessageFor(x => x.Email)
    </div>
    <div class="form-group col-md-4">
      @Html.LabelFor(x => x.Dob, new { @class = "control-label required" })@Html.EditorFor(x => x.Dob, new { htmlAttributes = new { @class = "form-control required datepicker" } })
      @Html.ValidationMessageFor(x => x.Dob)
    </div>
  </div>
  <div class="row">
    <div class="form-group col-md-6">
      @Html.LabelFor(x => x.Address, new { @class = "control-label required" })@Html.EditorFor(x => x.Address, new { htmlAttributes = new { @class = "form-control required", maxlength = 150 } })
      @Html.ValidationMessageFor(x => x.Address)
    </div>
    <div class="form-group col-md-6">
      @Html.LabelFor(x => x.City, new { @class = "control-label required" })@Html.EditorFor(x => x.City, new { htmlAttributes = new { @class = "form-control required", maxlength = 50 } })
      @Html.ValidationMessageFor(x => x.City)
    </div>
  </div>
  <div class="row">
    <div class="form-group col-md-4">
      @Html.LabelFor(x => x.ProvState, new { @class = "control-label required" })@Html.EditorFor(x => x.ProvState, new { htmlAttributes = new { @class = "form-control required", maxlength = 2 } })
      @Html.ValidationMessageFor(x => x.ProvState)
    </div>
    <div class="form-group col-md-4">
      @Html.LabelFor(x => x.CountryId, new { @class = "control-label required" })@Html.DropDownListFor(x => x.CountryId, Model.CountryList, "« ‹ Select › »", new { @class = "form-control required" })
      @Html.ValidationMessageFor(x => x.CountryId)
    </div>
    <div class="form-group col-md-4">
      @Html.LabelFor(x => x.Postal, new { @class = "control-label" })@Html.EditorFor(x => x.Postal, new { htmlAttributes = new { @class = "form-control postalcode", maxlength = 7 } })
      @Html.ValidationMessageFor(x => x.Postal)
    </div>
  </div>
  <div class="row">
    <div class="form-group col-md-4">
      @Html.LabelFor(x => x.HowHeardId, new { @class = "control-label required" })@Html.DropDownListFor(x => x.HowHeardId, Model.HowHeardList, "« ‹ Select › »", new { @class = "form-control required" })
      @Html.ValidationMessageFor(x => x.HowHeardId)
    </div>
    <div class="form-group col-md-4">
      @Html.LabelFor(x => x.TrainingSiteId, new { @class = "control-label required" })@Html.DropDownListFor(x => x.TrainingSiteId, Model.TrainingSiteList, "« ‹ Select › »", new { @class = "form-control required" })
      @Html.ValidationMessageFor(x => x.TrainingSiteId)
    </div>
    <div class="form-group col-md-4">
      @Html.LabelFor(x => x.Comments, new { @class = "control-label" })@Html.TextAreaFor(x => x.Comments, new { @class = "form-control", rows = 3 })
      @Html.ValidationMessageFor(x => x.Comments)
    </div>
  </div>
  <div class="blank-divider clearfix" style="height:30px;"></div>
  <div class="row">
    <div class="form-group col-md-6">&nbsp;</div>
    <div class="form-group col-md-6"><label class="control-label">&nbsp;</label><input type="submit" value="Submit Request" alt="Submit Request" title="Submit Request" class="btn btn-default btn-success" /></div>
  </div>
}

I am utterly stumped as to why Fluent Validation is only firing under extremely limited circumstances.

Please understand that when it does fire -- post-submission greedy validation for all other fields, server-side validation for the drop-down menus -- all messages are perfectly as expected.

However, validation is not firing for both client-side and server-side for any field. If it fires server-side, it fails to fire client-side. If it fires client side, it does so only under limited conditions (string length not sufficient, etc.) and it then refuses to fire server-side.

What is not working is the usual validation and any attempt to catch .NotEmpty() and .NotNull().


EDIT:

I can’t see how this is possible (nothing is being loaded from the DB, only inserted into it), but could string-field validation be buggered up by the format of the database’s fields? Could it being an nchar be an issue here?

Plus, I am using a custom model to gather the data, before adding it to a Data Model for insertion into the DB, so we have even more distance from the DB structure. Theoretically I couldn’t see how such a relationship is possible prior to moving the data from the ViewModel to the DataModel.


EDIT 2:

The .Cascade(CascadeMode.StopOnFirstFailure) made no difference, the issues occur with or without these in the Validator class.


EDIT 3:

Let me be more precise about the greedy validation. In all cases, any .NotEmpty() and .NotNull() validations still fail to fire, so simply navigating from one field to the next (after hitting Submit) will fail to trigger greedy validation. It’s only when you put something in, and it’s not sufficient for other validation (too short, not a valid eMail, not a valid phone number etc.) that the greedy validation fires. That is why I came up with my first edit (above), because maybe the system is not seeing those string fields as either empty or null, even when they are.


EDIT 4:

More WTF bizarreness. When I put in a partial/incomplete string into something that does more than just length analysis -- such as only the first half of an eMail into the eMail field -- and then hitting Submit, THE SERVER-SIDE VALIDATION KICKS IN FOR ALL STRING FIELDS, EVEN THE NULL/EMPTY ONES.

Like, seriously Whisky. Tango. Foxtrot.


EDIT 5:

WTF x10: Edit 4 only happens if the three drop-downs have been selected. If any one of the three drop-downs are still un-selected, server-side validation fails to fire for any text field.

Plus, if all three drop-downs have been selected, full validation using .NotEmpty() and .NotNull() suddenly succeeds on all text fields, including both server-side and client-side greedy validation.

Holy tamale. This is getting bizarre.

I'm trying to redirect 2 parameters:

<asp:HyperLink runat="server" id="h1" NavigateUrl='OrderFromSupplies.aspx?Gender=<%#Eval("Gender") %>&<%#Eval("Name")%>'><%#Eval("Name") %></asp:HyperLink><br/>

And that is the url I get:

http://localhost:31397/user/admin/OrderFromSupplies.aspx?Gender=%3C%#Eval(%22Gender%22)%20%%3E&%3C%#Eval(%22Name%22)%%3E How can I do this?

I have a web application running on Windows Server 2012R2 and IIS 8. The Web application use Windows Authentication to verifie de user. When I test de login on server there is no problem, but when I trie from another computer I got the error:

"A specified logon session does not exist. it may already have been terminated".

I have a survey page in my website which is used to find the best place for the customer can live in USA. Here are the example questions and answers:

1.Are you willing to live in urban area?

yes

no

No Preference

2. What is your cost of preference?

low

high

No Preference

3. Do you like sunshine?

yes

no

No Preference

Which is the best way to get customers input with multiple combinations and 
return the results Asp.net MVC?

In my controller class I have below code to check customer inputs:

if(model.Is_Urban && model.Islowcost && model.Is_sunshine)
{
model.result = "Your best place to live is California"
}

Instead of using multiple if else condition is there a best way to check the 
multiple combinations of users input?

I just feel like tried everything. Yesterday I installed the Visual Studio 2017 Enterprise and updated it to the last version (15.7.2). I chose the necessary web components in the Visual Studio Installer, tried to execute the devenv /InstallVSTemplates, tried to repair Visual Studio. None of this helped me, I still can not find the ASP.NET Core Application under .NET Core in Visual Studio.

I also installed .NET Core SDK 2.1.200 x86 and x64 manually, but it didn't help me.

I tried several times to re-install the web-components and each time I received an error like the third screenshot. But I can not guarantee that this error has anything to do with ASP.NET Core. I tried to solve this error, but could not find a solution.

I ran out of ideas. Could someone help me? What should I do to make the components appear in the program?

Here the ASP.NET Core Application is missing!

All the components that I choosed

Installation Error

When publishing my ASP.Net Website (not a Web Application), the publisher does not include the Web.ConnectionStrings.config file that is next to the web.config. This is required since my web config looks like this:

<connectionStrings configSource="Web.ConnectionStrings.config"/>

How can I get a File System Publish to include files that Visual Studio seems to be ignoring. Please note that this is a website created using [File] > [New Website] in Visual Studio, not a [File] > [New Project] ASP.Net site so Content=Include will not work.

Steps to reproduce:

  1. In Visual Studio: File > New > Website..
  2. Create the Web.ConnectionStrings.config xml document (see ConnectionStrings.config code below).
  3. In the web config link up the Web.ConnectionStrings.config file to the Web.Config file (see Web.config code below)
  4. Publish the website to a folder on your file system, the Web.ConnectionStrings.config doesn't move with the rest of the files.

Web.config:

<configuration>
  <connectionStrings configSource="Web.ConnectionStrings.config"/>
  ..

Web.ConnectionStrings.config:

<?xml version="1.0" encoding="utf-8" ?>
<connectionStrings>
  <add name="connString" connectionString="yourConnectionstringhere"/>
</connectionStrings>

I got two working asp.net projects - API and site itself. I am trying to deploy it to one instance of Azure App service. But I got working configurations only if I deploy it to app's subfolder, and create non root virtual applications, e.g.:

enter image description here

But if I am trying to make root app for site:

enter image description here

I got problem with API project - it fails to work, cause it is trying to load Web.config from 'root' virtual application:

enter image description here

How could I made virtual app to load its own config file - not from the root app?

my access database wont update with this code what seems to be the problem? i have tried a lot of methods for updating my access database with no sucsess please guys some help.

protected void Btnupdate_Click(object sender, EventArgs e)
    {
        foreach (RepeaterItem RI in rptEdit.Items)
        {
            Label id = RI.FindControl("Pid") as Label;
            TextBox prdname = RI.FindControl("prdname") as TextBox;
            TextBox prdprice = RI.FindControl("prdprice") as TextBox;
            TextBox prdshortdesc = RI.FindControl("prdshortdesc") as TextBox;
            TextBox prdtype = RI.FindControl("prdtype") as TextBox;
            TextBox prdbrand = RI.FindControl("prdbrand") as TextBox;

            int updated;
            string connection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\Table.accdb";
            using (var conn = new OleDbConnection(connection))
            {
                conn.Open();
                string updSql = @"UPDATE ProductList SET
                    Pname = '" + prdname.Text + "' WHERE Pid = ?";
                using (var cmd = new OleDbCommand(updSql, conn))
                {
                    cmd.Parameters.Add("@Pname", OleDbType.VarChar).Value = prdname.Text;
                    updated = cmd.ExecuteNonQuery();
                    conn.Dispose();
                    conn.Close();
                }
            }
        }
    }

I have a solution that has 10 projects. 1 web site and 1 web service.

I setup a continuous deployment in Azure for the web app. The continuous deployment is confused due to the multiple projects. How do i scope my deployment to deploy the web site correctly.

The error is

Errors (1)
Error: More than one package matched with specified pattern: D:\a\r1\a\**\*.zip. Please restrain the search pattern.
Work items

enter image description here

I'm currently calling an iFrame within a modal window, and the page in the iFrame uses a socket connection. I need that when the modal is close, it also "closes" the page in the iFrame so the connection is kill, and in case of re-open, that it also draws again the iFrame as new so I can re-connect. Is this possible?

I thank anyone who can help me.

Here is my controller

    [HttpGet]
    public IActionResult Unregister(LinkedServiceTable lst)
    {
        lst.BuildLinkedServices();
        var model = new LinkedServiceTableViewModel
        {
            LinkedServices = GetLinkedServices(lst)
        };
        return View(model);
    }

    [HttpPost]
    public IActionResult Unregister(LinkedServiceTableViewModel vm)
    {
        return View(vm);
    }

    private IEnumerable<SelectListItem> GetLinkedServices(LinkedServiceTable lst)
    {
        var roles = lst.LinkedServices.Select(x => new SelectListItem
        {
            Value = x.LinkedServiceId.ToString(),
            Text = x.ServiceName
        });
        return new SelectList(roles, "Value", "Text");
    }

Here is my razor view

@model CDIWeb.ViewModels.LinkedServiceTableViewModel
@{
    ViewData["Title"] = "Unregister Linked Service";
}

<h2>@ViewData["Title"]</h2>

<form action="/LinkedService/Unregister" method="post">
    @Html.LabelFor(m => m.SelectedLinkedServiceId)
    @Html.DropDownListFor(m => m.SelectedLinkedServiceId, Model.LinkedServices)
    <button type="submit" value="Submit">Submit</button>
</form>

All I want to do is submit myrazor view, then redirect back to the same page with the submited option on the dropdown selected. However, I am getting this error on HttpPost view, the HttpGet view is working fine and I am able to submit successfully.

InvalidOperationException: The ViewData item that has the key 'SelectedLinkedServiceId' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'.

Any ideas on why this is happening and how to fix it?

I have a simple IEnumerable that I am writing to a in a cshtml page. I'd like to add totals to the table on change of Entity, along the lines of:

Entity Cat Amount
ABC xxx 1,000
ABC yyy 2,000
ABC Total 3,000

I've been trying to do this inside the @foreach loop of the Model in cshtml, but can't work out how to use the combination of c# and html to achieve it.

So would be happy to learn a more appropriate approach. Also happy to understand how to mix c# and html if this is the best approach.

What I've been trying so far:

@{ string previousEntity = null; 
   decimal total = 0; 
 }
@foreach(var row in Model)
{
   if ((row.Entity != previousEntity) && (previousEntity != null))
   {
      <tr>
        <td>@previousEntity</td>
        <td>Total</td>
        <td>@total</td>
      </tr>
      total = 0;
   }
   <tr>
      <td>@row.Entity</td>
     etc.

This results in the c# code appearing on the page in the browser
THANKS

Razor page -

<form action="/Home/Register" method="post">
    <select asp-for="MyEnum" asp-items="Html.GetEnumSelectList<MyEnum>()"></select>
    ...
    ...
    <button type="submit" value="Submit">Submit</button>
</form>

ViewModel -

public class MyViewModel
{
    public MyEnum? MyEnum{ get; set; }
    public IConfig Config { get; set; }
}

Configs

public interface IConfig 
{
    string Json { get; set; }
    string BuildJson();
}

public class FirstConfig : IConfig
{
    public string ValueA { get; set; }

    public string Json
    {
        get => BuildJson();
        set { throw new NotImplementedException(); }
    }
    public string BuildJson()
    {
        ...
    }
}

public class SecondConfig : IConfig
{
    public int ValueA { get; set; }
    public int ValueB { get; set; }
    public int ValueC { get; set; }

    public string Json
    {
        get => BuildJson();
        set { throw new NotImplementedException(); }
    }
    public string BuildJson()
    {
        ...
    }
}

public class ThirdConfig : IConfig
{
    public string ValueA { get; set; }
    public int ValueB { get; set; }
    public string ValueC { get; set; }
    public string ValueD { get; set; }
    public string ValueE { get; set; }

    public string Json
    {
        get => BuildJson();
        set { throw new NotImplementedException(); }
    }
    public string BuildJson()
    {
        ...
    }
}

So currently I have MyEnum being displayed in a form which is attached to MyViewModel. But next, i am having some difficulties. Based on what Enum is selected, I want a different set of bindings to be displayed (If MyEnum.FirstConfig is selected, I want FirstConfig to be displayed, and so forth. Then when posted, I want to somehow build those bindings into a FirstConfig object and then set Config in MyViewModel to the FirstConfig object that was submitted in the post. Is something like this possible? How would it be accomplished?

Hi Is there an available App sample for an Asp.Net Core 2.0 MVC using Entity framework that has search between 2 dates ability? It will be greatly appriciated!

I have a razor view like the following:

@model WebCoreFly.Models.ViewModels.SearchFlightInfoCollList

@foreach (var fcoll in Model)
{
<div class="row">
    <div class="col-md-4">
        <p>From @fcoll.depFlight.Location , @fcoll.depFlight.Country (@fcoll.depFlight.Airport) Leaves at: @fcoll.depFlight.Time</p>
        <p>To @fcoll.depFlight.ArriveLoc , @fcoll.depFlight.ArriveCountry (@fcoll.depFlight.ArriveAirport) arrives at: @fcoll.depFlight.ArriveTime</p>
    </div>
    <div class="col-md-2">
        <p>
            Tarif: @fcoll.depFlight.Tarif 
        </p>
        <a asp-action="BookingForm">Choose <a>
    </div>
</div>
}

It is basically a list that outputs the collection of my data. Now for each item I need a link or a button that will launch a controller (that I called BookingForm and will pass to it the data of the item chosen by the user. How can I achieve this? In html I know what I would do I would create a link and pass some info via get, but how to achieve it in a mvc context?

Register Table

Meeting Table the RegisterID is also of type int

What I basically want to do is to get the ID of Sanni Jamiu from Register when it is filled in a form in a modal and save it to the Meeting tablevar user = db.QuerySingle("INSERT INTO Meeting(RegisterID) SELECT ID FROM Register WHERE LOWER(Name) = LOWER(@0)",Name1);

I am working on an application in .Net Core 2.0 Razor Pages using Entity Framework (Not MVC), i.e. There are models and Razor Page using one of those models. Every Razor page has a .cshtml page(view page which can also have c# code within razor syntax), and a .cshtml.cs file which is the code-behind consisting of C# code with Get and Post methods.

I have tried all possible research on the internet including the following links which use JS or JQuery: http://jsfiddle.net/k148pk76/1/ Countrylawstable is the model I am using. I tried using Javascript which is getting me the frontend but the values aren't reflecting on the database. The GetCommonCodes is a class which helps get the list of countries from the database. I want the country and state names to be populated from the database. Someone please help, I have tried many solutions on the internet but all of them use the MVC. Below is my code:

..
... 
<div class="form-group">
<label class="control-label">Country</label>   
<select asp-for="Countrylawstable.Country" class="form-control">
<option value="N/A"> Please Select Country</option>
@foreach (var item in DocumintAdmin.Models.GetCommonCodes.Commoncodeslist)
    {
        if (item.Refcodetype.Equals("COUNTRY"))
        {
            <option value="@item.Refcode"> @item.Refdesc</option>
        }
    }
</select>
<span asp-validation-for="Countrylawstable.Country" class="text-danger"> 
</span>
</div>


<div class="form-group">
<label class="control-label">State</label>
<select asp-for="Countrylawstable.Countrystate" class="form-control" >
<option value=""disabled selected>Select State</option>

</select>
<span asp-validation-for="Countrylawstable.Countrystate"></span>
</div>