.NET MVC

417

Solutions

301

Contributors

Microsoft’s ASP.NET MVC is a web application framework that implements the model–view–controller (MVC) pattern. As an open-source software, it’s set apart from the ASP.NET Web Forms component, which is proprietary.

Share tech news, updates, or what's on your mind.

Sign up to Post

Looking to implement possible actions after login such as:

MFA
Change Password
Accept License Agreement
Watch an AD

After a user has validated their credentials, multiple actions may need to be executed before they can use the app. What would be the best way to design this? Keep in mind that they all need to happen in a specific  order and they each need to know that the action before it succeeded.  So if a user logs in and the password expired, they would need a screen to change their password and then they would need to accept an agreement.

If you have any questions please let me know.
0
i use area in MVC like below URL
https://www.c-sharpcorner.com/article/simple-modularity-through-areas-in-asp-net-mvc/

Under View BLUE, if I want to create /Domain/Blue/SubFolder/1

http://localhost:2714/Parent/Blue/List/Index, how can I do that? The example shown I can only add one controller
0
Originally, I have a website written by asp.net www.abc.com and have many landing page called landing1.aspx landing2.aspx and etc.

We recently re-build the website written in mvc and now we want to fix the redirect.
assume someone search our webpage on google.com and have www.abc.com/landing1.aspx and landing2.aspx and etc.

how can we take all of the aspx webpages and redirect back to our domain www.abc.com?

Thanks,
0
I have very simple mvc/c# and have a controller e.g. https://www.abc.com/webAPI/ 
And accept parameter like https://www.abc.com/webAPI/100

And now i have a website called https://www.xyz.com and I want to write a Ajax codes called ‘https//www.abc.com/webAPI/120

Will it has any cross domain issue? I tried to use www.abc.ocm/webAPI/ as my end point for multiple websites.
0
Hello,
I am working with a MVC web project.  I have a save button on a page that calls a javascript function when clicked.

<input type="submit" value="Save" class="btn btn-default" name="action" onclick="Confirm()" />

Open in new window


How can I make this button call the javascript function only if the status dropdown is set to selection "Closed"?

This is the **javascript**

    function Confirm() {
    var input = $("<input />");
    input.attr("type", "hidden").attr("name", "confirm_value");
        if (confirm("Do you want to save the ticket to the knowledge base archive?")) {
            input.val("Yes");
        } 
        else {
            input.val("No");
        }
    $("form")[0].appendChild(input[0]);
    }

Open in new window


This is the HTML code for the dropdown:

@Html.LabelFor(model => model.vcStatus, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownListFor(
                                        m => m.vcStatus,      
                                        Model.StatusList)     
                                        
                    @Html.ValidationMessageFor(model => model.vcStatus, "", new { @class = "text-danger" })
                </div>

Open in new window




Thank you very much for your help.
0
Hello,
I am getting my last name back as "Webster" but I would like to get JWebster(first initial of my first name and last name) or Fieldaero\jim.webster.  How could I do that?
This is the code I have:

In the Controller:
var userName = Request.RequestContext.HttpContext.User.Identity.Name;
ViewBag.Name = userName;

Open in new window


In the View:
@Html.Label((string)ViewBag.Name)

Open in new window



If I do it directly from the view with code
@Request.RequestContext.HttpContext.User.Identity.Name

Open in new window

I get what I want, that is Fieldaero\jim.webster,  but I do not know how to get the same result in the controller.  I will then use the value in the controller to execute other code.  Thank you very much for your help!
0
Hi,

I want to start saying that I am new to MVC web app.
In debug I simply get my username, then there is a label that displays it, in my case it is nsanta.  It works when I am in debug but it does not in the IIS published version.  This is the text I get in the label when I go to the website  
"IIS APPPOOL\DefaultAppPool"

This is the code that works in debug.  They all work, it is just different ways I have tried:
In the Controller:
1-
public string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

Open in new window


2-
var testuserName = HttpContext.User.Identity.Name;

Open in new window


3-
var testanotheruser = WindowsIdentity.GetCurrent();
            var testuserName = testanotheruser.Name;
ViewBag.Name = testuserName;

Open in new window


In the View:
@Html.Label((string)ViewBag.Name)

Open in new window


Again, they all work in debug but when I go to the website it does not.  


Also, I do not know if it matters but I included a screenshot of the project properties. Another forum mentioned to set Anonymous Authentication to Disabled and Windows Authentication to Enabled.  The second screenshot shows authentication in IIS.  Please help, I do not know what else to do.
Project-Properties.JPG

Authentication.JPG
0
Hello,

I am trying to get the username in an MVC Web app which is published to an IIS, but it does not work.  
These are the 3 things I have tried:
1)
public string userName = System.Environment.UserName;

Open in new window


2)
public string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

Open in new window


3)
In the view:
@Html.Label((string)ViewBag.Name)

Open in new window

In the controller:
ViewBag.Name = userName;

Open in new window



It works when I debug the app locally on my machine.  Although, when I go to the website it does not get my username, instead it looks like it gets something from the IIS?  I simply would like to get the username of the person on the website and no other functionalities.  Could you please help me with this?  Thank you very much in advance.
1
My goal is to move a (JsonResult StoreSchedulerMapViewData) method into an (public ActionResult SchedulerMapView) function that is in my controller but I'm unsure how to modify my .ajax call.

Any input is greatly appreciated: My main goal is to create a GUID token and not use my memory cache..

Here is the before code and what I tried to attempt.... Unfortunately I'm trying to modify my .ajax to call an IAction result and I can't seem to figure this out...

All I'm trying to do is not use the MemoryCache.Default.Add(guidToken, schedulerMapPrms, DateTime.Now.AddMinutes(1)); on my JsonResult StoreSchedulerMapViewData and just use the main functionality to my second controller

 public JsonResult StoreSchedulerMapViewData(string route, DateTime scheduleDate, string[] serviceIds)
    {
        var guidToken = LoggedInUser.ID.Trim() + System.Guid.NewGuid().ToString().Trim();
        var serviceIdsList = new List<int>();

        for (int i = 0; i < serviceIds.Count(); i++)
            serviceIdsList.Add(Convert.ToInt32(serviceIds.ElementAt(i)));

        var schedulerMapPrms = new SchedulerMapParams()
        {
            Route = route,
            ScheduledDate = scheduleDate,
            ServiceIds = serviceIdsList
        };
        var result = new Models.ResponseObject() { Success = true, Message = guidToken, Model = serviceIds };
        MemoryCache.Default.Add(guidToken, schedulerMapPrms, DateTime.Now.AddMinutes(1));
        return Json(result);
    }

Open in new window


public ActionResult SchedulerMapView


Open in new window

0
Hi, I receive the following code error when trying to run my MVC application from localhost using Microsoft AD. When debugging the application I noticed that GetExternalLoginInfoAsync returns null. However, the application runs fine on the web. What am I missing? Somebody please help. I have posted my code below the error message:

-----------------------------------
Server Error in '/' Application.

Object reference not set to an instance of an object.
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

 Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 140:        {
Line 141:            ExternalLoginInfo loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
Line 142:            ClaimsIdentity claimsIdentity = loginInfo.ExternalIdentity;
Line 143:            ApplicationUser applicationUser = new ApplicationUser(claimsIdentity);
Line 144:            IdentityResult result = await UserManager.PersistAsync(applicationUser);
-------------------------------------


My Code
-------------------------------------

using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using …
0
Hello,

how do I include a link in an email that when clicked it would display data for one record only?

Right now I have a datatable in the index page that displays all records when the app opens up. When a change to a record is made an email is sent out with the id number of the record that was edited.

I am supposing I have to create another view just for this? I was thinking I need to implement a GET action in a controller that accepts id as a parameter, searches the underlying data store and returns appropriate record.

Also, I found this Open Specified ASP.NET MVC Views From Hyperlinks Inside Email Body but I cannot quite understand what is going on as there is login stuff and other things involved as well.

How do I go about this as I have never done it before? Could you please provide some example code? Thanks a lot.

THIS IS THE CODE I HAVE SO FAR WHICH WORKS BUT IT IS MISSING THE PIECE I AM ASKING FOR:
[HttpPost]
public ActionResult EditOneRecord(Ticket tix, string action, string confirm_value)
{
    if (action == "Save")
    {
        using (DBModel db = new DBModel())
        {
                //Send email to user if IT edits the record     
                if (userName != tix.vcAssignedTo)
                { 
                    SmtpClient client = new SmtpClient();      
                    MailMessage mailMessage = new MailMessage();
                    mailMessage.From = new MailAddress("nsantagata@fieldaero.com");
            

Open in new window

0
Hi,
How do I include a link in an email that when clicked it would display data for one record only?
Right now I have a datatable in the index page that displays all records when the app opens up. When a change to a record is made an email is sent out with the id number of the record that was edited.
I am supposing I have to create another view just for this?

How do I go about this as I have never done it before? Could you please provide some example code? Thanks a lot.
0
My MVC website using dropzone to capture photos. and everything is working okay in the following codes.

My question is: After the upload is completed, I want to store file photo name back into the html form.
The following codes already capture the file photo name. However, since user can keep adding & removing the photo,
I want to store list of the photo that already uploaded into html form as list. So when the final submit button is clicked,
I can get the list of photo file name and save into the database.




  <script>
                            Dropzone.options.myAwesomeDropzone = {
                                init: function () {
                                    this.on("removedfile", function (file) {
                                        alert("Are you sure you want to remove this photo " + file.name);
                                        //write ajax codes to remove this file
                                    });
                                }
                            };

                            Dropzone.options.myAwesomeDropzone = {
                                init: function () {
                                    this.on("complete", function (file) {
                                        alert("Save File:  " + file.xhr.responseText);                                        
                                    });
                                }
                            };

                          
               

Open in new window

0
i have simple mvc web app using c#.
do you know any drag & drop & remove photo codes I can use?
0
I am just learning EF and trying to execute a stored procedure to return a record from a database table.
I am getting  an error on the line:
TimeClockRecordsIO thisrec = context.TimeClockRecordsIO.SqlQuery("dbo.GetTimeClockRecordsIOLastClockIn @Pemployeeid", 1);

Open in new window

In the controller Action.
The entire Action is:
public ActionResult ClockInOut()
{
    using (var context = new TimeClockDec2019Entities2())
    {
        var blogId = 1;
        //'TimeClockRecordsIO blogs = context.TimeClockRecordsIOs.SqlQuery("dbo.GetTimeClockRecordsIOLastClockIn @Pemployeeid", 1);
        TimeClockRecordsIO thisrec = context.TimeClockRecordsIO.SqlQuery("dbo.GetTimeClockRecordsIOLastClockIn @Pemployeeid", 1);
        return View(thisrec);
    }
}

Open in new window


The line section:
context.TimeClockRecordsIOs.SqlQuery("dbo.GetTimeClockRecordsIOLastClockIn @Pemployeeid", 1)

Open in new window

Is saying:
“Cannot implicitly convert type system.data.entity.infrastructure.dbsqlQuery< TCDec2019.Models.TimeClockRecordsIO>’ to TCDec2019Models.TimeClockRecordsIO”

Open in new window


I assume I need to do some sort of conversion or change one of the settings in this line but I cannot figure out how to do it.
More Info:
The table name in my database is:
TimeClockRecordsIO
This is a simple stored procedure that works and returns the correct record when executed independently.

Any help would be appreciated
Thank you
0
Hi Folks,

I've a web application. The upload file control has valid data type i.e. .txt,.doc,.jpg,.pdf and restricted with .EXE extension. But, if user can rename .EXE extension & upload.
How to prevent .EXE file upload with renaming extension? Do you have thoughts?

Best Regards,
Mohit Pandit
0
Hi,
When I click on "Knowledge" tab(see attached) the data shows but the datatable does not get implemented.  What is the mistake I am making?  I could not find a solution as I seem to do everything correctly.  Attached is shown how the data appears when I click on the tab in question.  Thank you.Datatable-Look.JPG
Here is my code:

@model IEnumerable<HelpDeskSupport.Models.KnowledgeBaseModel>

@{
    Layout = null;
}

<!DOCTYPE html>

<head>

    <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
    <link href="jquery.datatables.yadcf.css" rel="stylesheet" type="text/css" />

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
    <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
    <script src="jquery.dataTables.yadcf.js"></script>

    <style>
        .label {
            padding: 0px 10px 0px 10px;
            border: 1px solid #ccc;
            -moz-border-radius: 1em; /* for mozilla-based browsers */
            -webkit-border-radius: 1em; /* for webkit-based browsers */
            border-radius: 1em; /* theoretically for 

Open in new window

0
We have an ASP.NET MVC applicaiton (Framework 4.5) deployed on IIS 8.0 on WINDOWS 2012 R2 Server. We got compliance issue from Security Team to Disable TLS 1.0 on this production server.
At present below settings are done on the server and it is verified using SSL LABs Test
SSL 2 : Disabled
SSL 3 : Disabled
TLS1.0: Enabled
TLS1.1: Disabled
TLS1.2: Enabled.

The application is working find with above settings. As soon as I disable TLS1.0 and perform server restart, the web application doesn't work and I get below error (also refer attached screenshot)
Can’t connect securely to this page
This might be because the site uses outdated or unsafe TLS security settings. If this keeps happening, try contacting the website’s owner.
Your TLS security settings aren’t set to the defaults, which could also be causing this error.


As soon as I revert back by Enabling TLS 1.0 the application seems to be working fine. Some how the application (or) the WIN 2012 server is using by default TLS1.0. How can change this to point to TLS 1.2.  So that the application works fine after disabling TLS 1.0

Below are few Troubleshooting I had performed and none of them worked.
1.  Added  below code at Action Result method of First Controller the application hits.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 

Open in new window


2.  Tried by upgrading the application from Framework 4.5 to 4.6.2 and deployed to the server. …
0
we use google hang out phone no. to forward the calls to our clients.
is it any api with c# library we can use to retrieve the call activities and etc.
0
I have membership website want to integrate with qr code. basically, the member will receive qr code by email. when the member show up the QR codes on paper or phone. we want to scan it and then save the record like check in date and time.

this is mvc c# app.

and how can I do that?
0
In response i have data as below:
<!DOCTYPE html>
<html>
<head>
<body>
.............
<div id="divtag">
                   
<table id='tblMainResult' width='100%' style='border: 0.5px solid #999999;' class='UploadAdjustmentTable'><tr style='height: 40px;'><td width='100%'><strong style='font-size: 12pt;'> XML Validation Results for: 30-Aug-2019</strong><br /><br /></td></tr><tr style='background-color: lightgray; height: 25px;'><td width='100%'><strong>Validate Presence of all 10 reports in XML </strong> </td></tr><tr><td width='100%' align='left' valign='top'><br /> Check 1:-Confirm XML contains 10 reports - <span style='color:green; font-weight: bold'>PASS </span><BR/><br /></td></tr><tr style='background-color: lightgray; height: 25px;'><td  width='100%'>
..........................
</td></tr></table></div><br /></td></tr><tr><td><br /> </td></tr>
</table>
</div>
...................
</body>
</head>
</html>

how to display only <div id="divtag"> content on page?


i need to display below after  success: function (response) { line?

   $.ajax({
                    url: '@Url.Action("CreateAndSubmitXML", "ExternalSubmission")',
                    data: JSON.stringify({
                        SelectedBusinessDate: selectedCobDate,
                        SelectedBusinessName: businessDatesText,
                        Reason: adjComments
                    }),
                    type: 'POST',
                    datatype: 'json',
            …
0
Hi,

i am getting html response in below variable which is bold below line:
     success: function (response) {

i need help on how to bind this html response to DIV tag which is below:

Code:

  $.ajax({
                    url: '@Url.Action("CreateAndSubmitXML", "ExternalSubmission")',
                    data: JSON.stringify({
                        SelectedBusinessDate: selectedCobDate,
                        SelectedBusinessName: businessDatesText,
                        Reason: adjComments
                    }),
                    type: 'POST',
                    datatype: 'json',
                    contentType: 'application/json; charset=utf-8',
                    success: function ([b]response[/b]) {
                        //alert("show");
                        debugger;
                        alert(response);
                        $('#divtag').html(response);

Open in new window




tried with below but not working:
1.   $('#divtag').html(response);

2. $(".result").html(response);
$(".result").append(response);
$(".result").txtresult(response);
<div class="result">
0
do u have a JavaScript code for the following

phone no mask (310)597-0000
ssn 111-11-1112

I just want to put it in separate J's file
but I don't want use the library.
0
I use jdatatable on mvc razor page. When it is loaded, everything is working. But when I click on sort button e.g. state, bond  name and etc. the following html part  is disappeared.
do you know how  to fix it?
In javascript, i used innerhtml or append and it still does  not work. thanks


td = td + "<tr>";
        td = td + "<td>" + "guidKey" + "</td>";
        td = td + "<td>" + "guidKey" + "</td>";
        td = td + "<td>" + "guidKey" + "</td>";
        td = td + "<td>" + "guidKey" + "</td>";
        td = td + "<td>" + "guidKey" + "</td>";
        td = td + "<td>" + "01/01/2011" + "</td>";
        td = td + "</tr>";



<table id="datatable2" class="table display responsive nowrap">
                <thead>
                    <tr>
                        <th class="wd-15p">Applicant</th>
                        <th class="wd-15p">State</th>
                        <th class="wd-20p">Bond Name</th>
                        <th class="wd-15p">Bond Amount</th>
                        <th class="wd-10p">Action</th>
                        <th class="wd-25p">Created On</th>
                    </tr>
                </thead>
                <tbody id="bodyData">
                    <tr>
                        <td>Tiger</td>
                        <td>Nixon</td>
                        <td>System Architect</td>
                        <td>2011/04/25</td>
                        <td>$320,800</td>
                        <td>t.nixon@datatables.net</td>
      

Open in new window

0
do u know any open sources codes can call Facebook, twilio and LinkedIn in the same time assume the message is the same?  in c# and mvc
0

.NET MVC

417

Solutions

301

Contributors

Microsoft’s ASP.NET MVC is a web application framework that implements the model–view–controller (MVC) pattern. As an open-source software, it’s set apart from the ASP.NET Web Forms component, which is proprietary.