目前的项目帮助请.. C#MVC 4新手在这里帮助! ! ! ! [英] Current project help please.. C# MVC 4 newbie here HELP! ! ! !

查看:105
本文介绍了目前的项目帮助请.. C#MVC 4新手在这里帮助! ! ! !的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我希望用户在初次登录后重置密码。我只需要UPDATE方法的帮助。在数据库中更新密码。





我的控制器



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.Mvc;
使用 jury_service.Models;

命名空间 jury_service.Controllers
{
public class NewpasswordController:Controller
{
//
// 获取:/ Newpassword /

public ActionResult Index()
{
return 查看() ;
}

[HttpPost] * blueerrorlinehere
public ActionResult CreatePassword(CreateNewInfo login)
{
if (ModelState.IsValid)
{
// 检索用户
var uname = login.UpdateUser(login);
var newpassword = login.UpdateUser(login);
var confirmnewpassword = login.UpdateUser(login);

if (uname!= null
{
if
(newpassword == confirmnewpassword)
{
return 重定向( );
}

else
{
ModelState.AddModelError( 错误 密码必须匹配);

}
return 查看();

}
}

}

// {
// if(ModelState.IsValid)
// {
// var ffcuser = UpdateInfoREcordByName(login.uname);

/ / // var valid = login.DoLogin();

// // if(valid)
// // {
// // //返回RedirectToAction(fccindex ,FCCLogin);
// //返回RedirectToAction(CreatePassword,新密码);
// //}
// ModelState.AddModelError(错误,错误的用户名和/或密码);
// ModelState.Clear();

// }
// return查看();
// }

public ActionResult CreatePassword()
{
return View();
}

public ActionResult CreateNewInfo()
{
return 查看();
}
}
}









查看



 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel.DataAnnotations;
使用 System.Linq;
使用 System.Web;
使用 System.Data.Entity;
使用 System.Web.Mvc;
使用 Newtonsoft.Json;
使用 System.Net;
使用 System.Web.Providers.Entities;
使用 jury_service.CommonService;

命名空间 jury_service.Models
{
public class CreateNewInfo:BaseModel
{

[显示(名称= 用户名)]
[必填]
public string uname { get ; set ; }

// [显示(名称=旧密码)]
// [必填]
// public string oldpassword {get;组; }

[显示(名称= 新密码 )]
[必填]
public string newpassword {获得; set ; }

[显示(名称= 确认密码)]
[必填]
public string confirmnewpassword {获得; set ; }

public CreateNewInfo(): base new WebClient(), new CommonClient(), new Factory() )
{

}


// public CreateNewInfo(WebClient客户端)
// {
// 客户端=客户端;
// }

// public FCC_Users infoModel;

// public FCC_Users info ;


// 公共列表< FCC_Users> infos;




public FCC_Users UpdateUser(CreateNewInfo login)
{
尝试
{
// //添加请求标题
// Client.Headers.Add (HttpRequestHeader.ContentType,application / json);
// //发出请求到API并返回结果
// 返回JsonConvert.DeserializeObject< FCC_Users>(Client.DownloadString (new Uri(Properties.Settings.Default.Api_Url +Info+?infoname =+ login.uname)));

// 创建Json对象

// 添加请求标题
Client.Headers.Add( HttpRequestHeader.ContentType, application / json);
// 向API发出请求并返回结果
return JsonConvert.DeserializeObject< FCC_Users>(Client.UploadString( new Uri(Properties.Settings.Default.Api_Url + Info + ?infoname = + login.uname)));




}
catch (例外情况)
{
return null ;
}


}

// public FCC_Users UpdateInfoREcordByName(string infoName)
// {

// Client.Headers.Add(HttpRequestHeader.ContentType,application / json);
// infoModel = JsonConvert.DeserializeObject< FCC_Users>(client.UploadString(client.DownloadString( url));
// 返回信息;
< span class =code-comment> //
}
// }

}
}





我尝试过:



错误:



[HttpPost] * blueerrorlinehere

public ActionResult CreatePassword(CreateNewInfo登录)



错误1'jury_service.Controllers.NewpasswordController.CreatePassword(jury_service) .Models.CreateNewInfo)':并非所有代码路径都返回一个值











括号内的错误行

返回JsonConvert.DeserializeObject< fcc_users>(Client.UploadString(new Uri(Properties.Settings.Default.Api_Url +Info) +?infoname =+ login.uname)));



错误信息

方法'UploadString'没有重载需要1 arguments

解决方案

  1. 方法 CreatePassword 有两个return语句。如果 ModelState.IsValid 的计算结果为false,则不返回任何内容。如果为true,如果 uname == null 仍然没有返回任何内容。
  2. return JsonConvert.DeserializeObject ... - 请提供错误信息。可能缺少某些东西,未定义等等。
  3. 查看 UploadString 的签名。最有可能的是,您尝试使用其中一种方法 System.Net.WebClient.UploadString 。看看他们的签名:

    WebClient.UploadString方法(System.Net)



    如您所见,期望一个或两个参数。您正在尝试传递 Uri ,但没有方法只期望此参数;你需要添加一个或两个字符串参数 - 请看最后两种方法。



    现在,错误#2很可能是由此错误间接引起的,所以请修复它。





我必须注意,您所面临的所有编译错误都清楚地由错误消息描述。你必须学习理解它们,这与理解语法和其他基础和基础语言和编程概念有关。



-SA

Basically I want users to reset password after initial login. I just need help with the UPDATE method.Updating password in database.


My controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using jury_service.Models;

namespace jury_service.Controllers
{
    public class NewpasswordController : Controller
    {
        //
        // GET: /Newpassword/

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]           *blueerrorlinehere
        public ActionResult CreatePassword(CreateNewInfo login)
        {
            if (ModelState.IsValid)
            {
                //Retrieve User
                var uname = login.UpdateUser(login);
                var newpassword = login.UpdateUser(login);
                var confirmnewpassword = login.UpdateUser(login);

                if (uname != null)
                {
                    if
                        (newpassword == confirmnewpassword)
                    {
                        return Redirect("");
                    }

                    else
                    {
                        ModelState.AddModelError("Error", "Passwords Must Match");

                    }
                    return View();

                }
            }

        }
    
        //{
        //    if (ModelState.IsValid)
        //    {
        //        var ffcuser = UpdateInfoREcordByName(login.uname);
                
        //        //var valid = login.DoLogin();

        //        //if (valid)
        //        //{
        //        //    //return RedirectToAction("fccindex", "FCCLogin");
        //        //    return RedirectToAction("CreatePassword", "New password");
        //        //}
        //        ModelState.AddModelError("Error", "Wrong Username and/or Password");
        //        ModelState.Clear();

        //    }
        //    return View();
        //}

        public ActionResult CreatePassword()
        {
            return View();
        }

        public ActionResult CreateNewInfo()
        {
            return View();
        }
    }
}





View

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Web.Mvc;
using Newtonsoft.Json;
using System.Net;
using System.Web.Providers.Entities;
using jury_service.CommonService;

namespace jury_service.Models
{
    public class CreateNewInfo : BaseModel
    {

        [Display(Name = "Username")]
        [Required]
        public string uname { get; set; }

        //[Display(Name = "Old Password")]
        //[Required]
        //public string oldpassword { get; set; }

        [Display(Name = "New Password")]
        [Required]
        public string newpassword { get; set; }

        [Display(Name = "Confirm Password")]
        [Required]
        public string confirmnewpassword { get; set; }

        public CreateNewInfo(): base(new WebClient(), new CommonClient(), new Factory())
        {

        }


        //public CreateNewInfo(WebClient client)
        //{
        //    Client = client;
        //}

        //public FCC_Users infoModel;

        //public FCC_Users info;


        //public List<FCC_Users> infos;




        public FCC_Users UpdateUser(CreateNewInfo login)
        {
            try
            {
            //    //Add Request Headers
            //    Client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
            //    //Make Request to API and return results
            //    return JsonConvert.DeserializeObject<FCC_Users>(Client.DownloadString(new Uri(Properties.Settings.Default.Api_Url + "Info" + "?infoname=" + login.uname)));

                //Create Json object
              
                //Add Request Headers
                Client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                //Make Request to API and return results
                return JsonConvert.DeserializeObject<FCC_Users>(Client.UploadString(new Uri(Properties.Settings.Default.Api_Url + "Info" + "?infoname=" + login.uname )));




            }
            catch (Exception ex)
            {
                return null;
            }


        }

        //        public FCC_Users UpdateInfoREcordByName(string infoName)
        //        {

        //            Client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
        //            infoModel = JsonConvert.DeserializeObject<FCC_Users>(client.UploadString(client.DownloadString(url));
        //            return info;
        //        }
        //}

    }
}



What I have tried:

Error:

[HttpPost] *blueerrorlinehere
public ActionResult CreatePassword(CreateNewInfo login)

Error 1 'jury_service.Controllers.NewpasswordController.CreatePassword(jury_service.Models.CreateNewInfo)': not all code paths return a value





Error line within the parentheses
return JsonConvert.DeserializeObject<fcc_users>(Client.UploadString(new Uri(Properties.Settings.Default.Api_Url + "Info" + "?infoname=" + login.uname )));

Error message
No overload for method 'UploadString' takes 1 arguments

解决方案

  1. The method CreatePassword has two return statements. If ModelState.IsValid evaluates to false, nothing is returned. In case of true, if uname == null still nothing is returned.
  2. return JsonConvert.DeserializeObject… — please provide error information. Something can be missing, underfined, etc.
  3. Look at the signature of UploadString. Most likely, you are trying to use one of the methods System.Net.WebClient.UploadString. Look at their signatures:
    WebClient.UploadString Method (System.Net).

    As you can see, the expect one or two parameters. You are trying to pass Uri, but there are no methods expecting only this parameter; you need to add one or two string parameters — please see two last methods.

    Now, it's very likely that the error #2 is indirectly caused by this error, so please fix it.



I must note that all the compilation errors you face are clearly described by the error messages, very clearly. You have to learn understanding them, which is linked to understanding of the syntax and other fundamental and elementary language and programming concepts.

—SA


这篇关于目前的项目帮助请.. C#MVC 4新手在这里帮助! ! ! !的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆