.NET MVC

294

Solutions

250

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

I have the following code that returns one record. I need to convert this to a list and return single or more than one.

public string GetApproverEmail()
        {
            try
            {

                var user =  (from x in DB.tbl_User
                        where x.Approver == true
                        select x).Single();

                var email = (from x in DB.tbl_GlobalUser
                                  where x.ID == user.UserID
                                  select x.Email).Single();

                return (email);

            }

            catch
            {
                return null;
            }
        }

Open in new window


This sends the email:

public static void Approve(tbl_ChangeRequest cr)
        {
            User user = new User();
            Email mail = new Email("Approval");
            string Email = user.GetApproverEmail();

            string body = ("This is an automated email.<br />" + "" +
                "text here"" +
                 " is ready for approval. <br />" + "<br />" +
             );

            mail.SetBody(body, true);
            mail.AddTo(Email);
            mail.AddCC("");

            mail.Send();
        }

Open in new window

0
Answering your cyber security questions
Answering your cyber security questions

It’s in the news. It’s the job title of the main character on every other tech thriller on TV and in the movies. It’s the hot topic in business boardrooms, university classrooms, and just about everywhere else. But what is cyber security, and how do you get a job in it?

I have searched on Google about creating view without controller but most of them shown me I can do it using redirect so I try out.

the result is because the app redirect so many time n it ends up it time out or generate error message.

if you have the same situation please show me how to handle this.

the reasons we don't want to use controller is because we will create many landing page from our web designer. and there is no need to generate any model, but we do want to use cshtml to do some server side work.

thanks
0
i have  @Html.Partial("~/Views/Shared/_ListingsSubEvent.cshtml", "13") on razor
how to capture the value(13) on _ListingsSubEvent.csthml?
0
Need Sitecore and .NET MVC practice site

I will be placed on a client location in a few weeks and at that time will be granted access to the existing Sitecore database. Until then, I need some hands on practice with Sitecore.

First, what is the correct term for a Sitecore file? It's not a database, but what term do you use to describe it?

I will be using Sitecore with .NET C# MVC.

I have Visual Studio installed and SSMS, but may need to put on SQL Server as well.

What can you suggest? I will also have no access to the source code until I am at the client location, so I just need something akin to a sandbox where I can play around. An existing, working MVC site with an integrated Sitecore demo database would be best.

What can you suggest?

Thanks
0
Tips to mastering Sitecore

I have a rare opportunity to invest lots of time into learning Sitecore, in preparation for a job integrating Sitecore with a .NET MVC application. So, the more I learn now, the further I can go in implementing Sitecore.

What videos and topics can you suggest I did into to make the most out of this one month deep dive into Sitecore.

And what related technologies might I also consider?

Thanks
0
i have very common mvc razor web app. and I want to create view without controller and also without using new folder.
I will have one folder called catchall, and I want all view that without controller stay inside of the catchall folder.

Is it possible? and how to do it?

Thanks
0
What .NET Technologies in a New MVC Application?

If you needed to architect a new  .NET MVC Application today, what would it consist of?

What version of .NET, MVC, might it be?
And what about Dependency Inversion?
What about Unit Testing?
What is your preferred Unit Test Framework?
What about AutoMapper?
How about a MOQ tool?

And what else am I forgetting to mention?

Thanks
0
Web URL re-routing and questions about HTAccess

I have used HTAccess (originated with Apache) a few years ago on an MVC site to re-route the URL and am posting a few questions about how to do this today.

1) Is HTAccess still a viable option for web URL re-routing?
2) Is there a different way for a .NET MVC to get this capability?
3) Does HTAccess re-route WITHOUT needing a recompilation?
4) Is this considered "URL re-writing"?

Thanks
0
I have a website and try to track client IP to locate his/her for better information tracking.
we use c#/mvc/razor.

any suggestions on what we can use?

Thanks
0
i use @HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) but it does not read https. it read http only. how to fix it?
0
Why Diversity in Tech Matters
LVL 13
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

I'm using Visual Studio 2017 with C#.
I want a user to input some letters into a textbox.  A model maps each letter to a number and returns the total.  how can I display the result (Total variable in the model) in a text area in the same view?

Home Controller
public ActionResult Cards()
        {
            return View();
        }
        public ActionResult Cards(CardModel C)
        {
            C.GetScore(C.Deck);
            return View();
        }

Open in new window


Cards View
@{
    ViewBag.Title = "Cards";
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>

<h2>Cards</h2>

    <h2>Please enter a number</h2>

      First name: <input type="text" name="Deck"><br>
      <textarea id="TextArea1" rows="2" cols="20"></textarea>
    <input type="submit" value="Submit">

Open in new window


Model
 public class CardModel
    {
        public string Deck { get; set; }
        public int GetScore(string s)
        {
            int score = 0;
            int totalScore = 0;
            string individualCard = "";
            //loop through each letter in string and convert to a number.
           return Total
}
}

Open in new window

1
I have mvc / razor app using ajax to make some transactions. everything is working fine.
But just we will add more parameters in data and It is going to super long list. so I want to find better way to handle this codes below.
I am thinking using json format passing value from front to the back. but do not know how to do it.

my question is:

1. is it best practice to use json format to pass list of value back and forth? If yes, can you show me how to do it with my codes below?
2. If json is not, can you suggest me what to do?
3. On the end - code behind. I do have lead class. and hope the best will be JsonResult CreateLead(Domain.Lead l) so I do not have to worry too much about list too long.


Thanks


$.ajax({
                                url: "/Home/CreateLead",
                                datatype: "text",
                                data:
                                {
                                    'firstname': document.getElementById("first-name").value,
                                    'lastname': document.getElementById("last-name").value,
                                    'phonenumber': document.getElementById("phone-number").value,
                                    'emailaddress': document.getElementById("email-address").value,
                                    'totalcountadult': document.getElementById("total-count-adult").value,
                                    'totalcountkid': 

Open in new window

0
I have object call Lead and a static method just like email template.
insid of using statement. is it possible to loop the Lead object and get the list of child object?
like this:

body = body.Replace("{displayname}", l.childname);

I have very long list and do not want to type line one by one.

Thank


public static string CreateEmailBody(Domain.Lead l, string templatePath)
        {
            string body = string.Empty;
            using (StreamReader reader = new StreamReader(System.Web.Hosting.HostingEnvironment.MapPath(templatePath)))
            {
                body = reader.ReadToEnd();
            }
            body = body.Replace("{FirstName}", l.FirstName);
            return body;
        }

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Domain
{
    public class Lead
    {
        [DisplayName("LeadID")]
        public int LeadID { get; set; }
        [DisplayName("Subject")]
        public string Subject { get; set; }
        [DisplayName("FirstName")]
        public string FirstName { get; set; }
        [DisplayName("LastName")]
        public string LastName { get; set; }
        [DisplayName("Email")]
        public string Email { get; set; }
        [DisplayName("MobilePhoneNo")]
        public string MobilePhoneNo { get; set; }
        [DisplayName("LeadStage")]
        public string LeadStage { get; set; }
        

Open in new window

0
Not sure why it always return 0 on last two decimal. like 4.00 5.00... I hope to see 4.23 e.g.

 @{ 
                                decimal totalRate=0;
                                foreach (Domain.Review fReviewItem in rv.ReviewSummary(f))
                                {
                                    totalRate = decimal.Parse(string.Format("{0:F2}",(fReviewItem.TotalRateCount / fReviewItem.TotalReviewCount))); 
                                } 
                                @totalRate;
                            } 

Open in new window

0
Hi Experts,
I have the following code. If the ModelState has error then I want to make the  email textbox red. Please help me how to do it. I am using c# MVC.
Thanks in advance!

@Display(Model.Content)
@using (Html.BeginFormAntiForgeryPost()) {
    @Html.ValidationSummary()
<div class="login-page">
    <h3>@T("Your email address")</h3>
    @Html.TextBox("email", string.Empty, new
    {
        maxlength = 100
    })
</div>


public ActionResult ForgotUserName() {
			var model = _LoginViewModelProvider.GetForgotUsernameViewModel();
			return View(model);
		}


[HttpPost]
		public ActionResult ForgotUserName(string email) {			
			if (!isValidEmail) {
				ModelState.AddModelError("_FORM", T("We're sorry. The information you provided does not match an account in our records."));
				return ForgotUserName();
			}
			
		}

Open in new window

0
I have PDF form that users can fill out and upload into our site.  I capture the fields and write to our database.  
I also allow users to edit the information thru edit forms in our site and allow them to export the PDF Form from our site.

I need to add a signature field to the PDF Form and capture this info if they upload the form.
I also need to allow a user to click a button to "Sign" the record and capture their signature info that I can then export to the PDF Form.

If I could just get my hands on a good example, it would be so helpful!
0
have mvc website that need form wizard step by step. anyone can suggest very simple one to understand?
0
I have a survey website written in mvc so you can image that I have alot of values that need to be captured. and I want to use local storage in javascript.
Is it good idea? I understood local resource has 10 mb as max size.

If you think it is not a good idea, what is the alternative? I do not plan to save them into DB.
0
I'm getting an error "Object reference not set to an instance of an object."
on this line in the cshtml
@foreach (var scheme in (List<SchemesMaster>)ViewBag.SchemeList)

to give you an overview:

I have a CSHTML page called paintimage.cshtml
Index.cshtml calls this by having this code   @Html.Action("PaintImage")

then in the homeController.cs  i have
"public ActionResult PaintImage()" which returns a    "return PartialView();"

Inside this code I add lots of stuff to the viewBag
i.e.
ViewBag.CameraID = _imageData.CameraID;

this works fine
However, I need to return a list of items, i've done this in the homecontroller
ViewBag.SchemesList = process.GetSchemes(camera.SiteId);
In the cs file, i can see this is populated fine
But when it gets to the html, its erroring when trying to foreach through the items in the list

what am I missing?
0
Active Protection takes the fight to cryptojacking
LVL 2
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Hello,

I am using obout custom control Grid for an application which is in ASP.NET web forms .
I want to replace this obout Grid with any other non-paid alternative control [like ng-grid in angularjs or so]
Can anyone tell how to replace obout Grid control with an alternative one which is equally good. If if yes , can you share an example of the same ?
0
How do i populate a combobox on a MVC VIEW FROM ELEMENTS FROM SQL SERVER DATATABLE USING VB.NET

Thank you
0
Dear experts,

I have created this code in the model of the MVC. objective is to populate the list of class object  in he model and the pass the populated list to contoller and the to view. this model is called login, i have the controller with the name loginController and the respective view

i don't know how to proceed from here.

I also seek advise  was this the best approach. to solve this.

I want to get data from sqlserver database and i populate it on a view. i dont want to use data entity framework.

Thank you



Imports System.Configuration
Imports System.Data.SqlClient

Public Class login
   
    Public Shared businessobj As New businesscls

    Public Class businesscls
        Public bid As String
        Public businesslst As New List(Of businesscls)
        Public Function hh() As businesscls
            hh = Nothing

            Dim sqlconn As SqlConnection
            Dim sqlcmd As New SqlCommand
            Dim spdr As SqlDataReader
            sqlconn = New SqlConnection( _
              "Server=M-PC\DBS;Initial Catalog=datranDb;Persist Security Info=True;User ID=MyUserID;Password=MyPassword;")
            sqlconn.Open()
            sqlcmd.Connection = sqlconn
            sqlcmd.CommandText = "select * from business"
            spdr = sqlcmd.ExecuteReader
            If spdr.HasRows Then
                Do While spdr.Read
                    businessobj.bid = spdr("bid")
                    businesslst.Add(businessobj)…
0
I'm getting the following error:  The objects “TableName” and “TableName” in the FROM clause have the same exposed names. Use correlation names to distinguish them

should I change my code as this. It look like it fixed the issue but I feel I haven't addressed the real problem. This is the line of code I changed:  "inner join #tempprogram  as  tp with (nolock) on program.progdefid = tp.progdefid";

Before:

    if (!searchCriteria.AllProgramCodes && searchCriteria.SelectedProgramCodes != null && searchCriteria.SelectedProgramCodes.Any())
            {
                baseQuery += Environment.NewLine + ServiceAssistantService.Tools.StringExtensions.GetObjectToTempTable(searchCriteria.SelectedProgramCodes.ToList(), "tempprogram", "progdefid", true);
                commonJoinClause += Environment.NewLine + "inner join #tempprogram with (nolock) on program.progdefid = #tempprogram.progdefid";
            }

Open in new window



After:
    if (!searchCriteria.AllProgramCodes && searchCriteria.SelectedProgramCodes != null && searchCriteria.SelectedProgramCodes.Any())
            {
                baseQuery += Environment.NewLine + ServiceAssistantService.Tools.StringExtensions.GetObjectToTempTable(searchCriteria.SelectedProgramCodes.ToList(), "tempprogram", "progdefid", true);
                commonJoinClause += Environment.NewLine + "inner join #tempprogram  as  tp with (nolock) on program.progdefid = tp.progdefid";
            }

Open in new window

0
I use itextsharp c# to populate value to pdf. The textbox is populated accordingly except the checkbox. And I do not know how to make the checkbox (Checked).

Just FYI. the checkbox export value is "Yes" on PDF document that I use.
0
Assume I have super simple MVC API. Our customer will use html jquery to consume the API.
I want to add one token per customer. for example,


customer A token: asdfasdfasfasfasd
customer B token: 23423423423234dsf


1. If the customer's webpage put above token there to consume my API, it has security concern because I can see the token in view source.
2. What is the simple way to implment API with token? I only have 2 to 5 API so I do not need very complex one.

[System.Web.Http.HttpGet]
        public string Get(string firstname)
	{
return firstname;

}

Open in new window

0

.NET MVC

294

Solutions

250

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.